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.
Hi Aman-K ,
I think, I would add a date dimension to start with. You can then add the date dimension to your model and create a relationship between your table and that dimension:
Create a Date Dimension in Power BI in 4 Steps - Step 1: Calendar Columns - RADACAD
Then you can add a flag to the dimension that provides you with the options in your slicers. Alternatively, you could also use the filter pane in Power BI. Another way by utilising the date dimension is that you show your metrics per week so the fluctuations be less noticable. Lastly, you could also add a rolling average measure which smoothes the lines a bit more:
Rolling 12 Months Average in DAX - SQLBI
Let me know if this helps 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
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:
- Ashish_Mathur1 year ago
Super User
Hi,
See if this YouTube video helps - Date Presets in Power BI (youtube.com)
- Anonymous1 year agoNot applicable
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.