filmov
tv
How to Filter a Power BI Measure by Selected Dates
Показать описание
Learn how to write a measure that will do a calculation as of a certain date forward.
Topic: Power BI, measures, DAX language
Functions: AVERAGE, CALCULATE, SELECTEDVALUE, FILTER, ALL
To jump to the final measure, go to this point in the video: 10:09
This was not mentioned in the video, but I would recommend making your slicer "single select" so that the "Average_Life_Expectancy_As_Of_Date_Selected" measure works as expected. To do this, click the slicer visual, go to the format visual pane, click slicer settings, and toggle single select to on.
If you would like to keep multi-select, I would recommend amending your code to the function below. You will see that the COALESCE and MIN lines are new (third to last line and last line). You may want to use MAX instead of MIN if you'd prefer to default to the latest selected date and forward. Keep it MIN if you'd prefer to see the earliest selected date and forward.
Average_Life_Expectancy_As_Of_Date_Selected =
CALCULATE(
'Measure'[Average_Life_Expectancy],
FILTER(
ALL(dsbb1_lifeexpectancy[Year]),
dsbb1_lifeexpectancy[Year] *INSERT GREATER THAN OR EQUAL TO SIGN HERE*
COALESCE(
SELECTEDVALUE(dsbb1_lifeexpectancy[Year]),
MIN(dsbb1_lifeexpectancy[Year])
)
)
)
*Note: YouTube does not support angled brackets in video details so you will have to update this inside of Power BI Desktop (SEE ALL CAPS ABOVE)
#PowerBI #measures #DAX #dates #DSBB
Topic: Power BI, measures, DAX language
Functions: AVERAGE, CALCULATE, SELECTEDVALUE, FILTER, ALL
To jump to the final measure, go to this point in the video: 10:09
This was not mentioned in the video, but I would recommend making your slicer "single select" so that the "Average_Life_Expectancy_As_Of_Date_Selected" measure works as expected. To do this, click the slicer visual, go to the format visual pane, click slicer settings, and toggle single select to on.
If you would like to keep multi-select, I would recommend amending your code to the function below. You will see that the COALESCE and MIN lines are new (third to last line and last line). You may want to use MAX instead of MIN if you'd prefer to default to the latest selected date and forward. Keep it MIN if you'd prefer to see the earliest selected date and forward.
Average_Life_Expectancy_As_Of_Date_Selected =
CALCULATE(
'Measure'[Average_Life_Expectancy],
FILTER(
ALL(dsbb1_lifeexpectancy[Year]),
dsbb1_lifeexpectancy[Year] *INSERT GREATER THAN OR EQUAL TO SIGN HERE*
COALESCE(
SELECTEDVALUE(dsbb1_lifeexpectancy[Year]),
MIN(dsbb1_lifeexpectancy[Year])
)
)
)
*Note: YouTube does not support angled brackets in video details so you will have to update this inside of Power BI Desktop (SEE ALL CAPS ABOVE)
#PowerBI #measures #DAX #dates #DSBB
Комментарии