Forum Discussion
Adding measures in Power BI report
- Anonymous1 year ago
Hi, Aman-K
I create a sample table:
Then create a new table, here is the dax:
TimePeriods = DATATABLE( "Period", STRING, { {"Today"}, {"Yesterday"}, {"Last 7 Days"}, {"Last 14 Days"}, {"Last 30 Days"} } )Create a new measure again, try the following DAX expression:
SelectedPeriod = VAR _date = MAX('Table'[Date]) RETURN SWITCH( SELECTEDVALUE(TimePeriods[Period]), "Today", IF(_date = TODAY(), "Today", BLANK()), "Yesterday", IF(_date= TODAY() - 1,"Yesterday", BLANK()), "Last 7 Days", IF(_date >= TODAY() - 7 && _date<= TODAY(), "Last 7 Days", BLANK()), "Last 14 Days", IF(_date >= TODAY() - 14 && _date <= TODAY(), "Last 14 Days", BLANK()), "Last 30 Days", IF(_date >= TODAY() - 30 && _date <= TODAY(), "Last 30 Days", BLANK()), 0 )Put this measure in Table view, and put TimePeriods's field in slicer, here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks tackytechtom - I hae created a dimension as described in above link. How can I add a slicer for "Yesterday", "Today", "Last 7 days", "Last 14 days, "Last 30 days"?
My dataset is as below:
Hi, Aman-K
I create a sample table:
Then create a new table, here is the dax:
TimePeriods = DATATABLE(
"Period", STRING,
{
{"Today"},
{"Yesterday"},
{"Last 7 Days"},
{"Last 14 Days"},
{"Last 30 Days"}
}
)
Create a new measure again, try the following DAX expression:
SelectedPeriod =
VAR _date = MAX('Table'[Date])
RETURN
SWITCH(
SELECTEDVALUE(TimePeriods[Period]),
"Today", IF(_date = TODAY(), "Today", BLANK()),
"Yesterday", IF(_date= TODAY() - 1,"Yesterday", BLANK()),
"Last 7 Days", IF(_date >= TODAY() - 7 && _date<= TODAY(), "Last 7 Days", BLANK()),
"Last 14 Days", IF(_date >= TODAY() - 14 && _date <= TODAY(), "Last 14 Days", BLANK()),
"Last 30 Days", IF(_date >= TODAY() - 30 && _date <= TODAY(), "Last 30 Days", BLANK()),
0
)
Put this measure in Table view, and put TimePeriods's field in slicer, here is my preview:
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.