简体   繁体   中英

Subtracting measure value from each row of a table in Microsoft Power BI

I have created two slicers in Power BI for Month and Year. These take the month and year value and in return generate a date.

Eg. Month - May & Year- 2019 generates 01/05/2019 with the help of the a measure formula :

MyFilterDate = DATE(SELECTEDVALUE(ListoY[Year]),SELECTEDVALUE(ListoM[Month],0),"01")

I want to subtract this date with one that is already in a column in the table.

I'm facing an issue when I try to subtract the measure from the existing column by writing DAX.

SUBVALNEW = DATEDIFF([MyFilterDate],Table[Date],DAY)

But when I try to do so, the result is not right. In fact when I try to check the value of [MyFilterDate] in the Data Model, it is not the same value as one calculated in the measure. (It instead looks like it displays the date in Table[Date])

Is there any way to subtract a Dynamically chosen date from a date in a column?
Any help would be appreciated.

I understand what your thinking patern is but power bi works a bit different. Dynamic measures cannot be used with calculated columns. When doing so the value of the measure is not set.

The way to go about this is by creating a Date table:

Date = CALENDAR(MIN(CalendarWeek[Date]);MAX(CalendarWeek[Date]))

Do NOT connect it to the model. From here you can make 2 slicers (based on the Date table). One your set to the month and the other to the year.

Next step is to adjust the MyFilterDate

MyFilterDate = DATE(SELECTEDVALUE('Date'[Date].[Year]);SELECTEDVALUE('Date'[Date].[MonthNo]);"01")

Make SUBVALNEW a measure (cannot be a column because it is dynamic!)

SUBVALNEW = DATEDIFF([MyFilterDate];SELECTEDVALUE(CalendarWeek[Date]) ;DAY)

Ass the Measuer to your visual, see end result below)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM