Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Aman-K
Helper III
Helper III

Adding measures in Power BI report

Hi guys,

 

I have created a report in Power BI which is extracting data from Google Analytics. I want to make few changes in my report so it looks like below :

AmanK_0-1727808849402.png

 

And a slicer as below:

AmanK_1-1727808944491.png

 

My Power BI report currently looks like below and it's not very clear . Can this be changed to look like above ? 

AmanK_2-1727809031381.png

The fields in my data set are as below:

AmanK_3-1727809069335.png

Can you help me with adding new measures in the report accordingly? Any help will be much appreciated. 

Thanks a lot. 

1 ACCEPTED SOLUTION

Hi, @Aman-K 

I create a sample table:

vyohuamsft_0-1729133878191.png

 

Then create a new table, here is the dax:

TimePeriods = DATATABLE(
    "Period", STRING,
    {
        {"Today"},
        {"Yesterday"},
        {"Last 7 Days"},
        {"Last 14 Days"},
        {"Last 30 Days"}
    }
)

vyohuamsft_1-1729134225625.png

 

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:

vyohuamsft_2-1729134364768.png

 

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.

View solution in original post

4 REPLIES 4
tackytechtom
Super User
Super User

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/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

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"? 

AmanK_0-1727816035715.png

My dataset is as below:

AmanK_1-1727816091230.pngAmanK_2-1727816109625.png

 

Hi, @Aman-K 

I create a sample table:

vyohuamsft_0-1729133878191.png

 

Then create a new table, here is the dax:

TimePeriods = DATATABLE(
    "Period", STRING,
    {
        {"Today"},
        {"Yesterday"},
        {"Last 7 Days"},
        {"Last 14 Days"},
        {"Last 30 Days"}
    }
)

vyohuamsft_1-1729134225625.png

 

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:

vyohuamsft_2-1729134364768.png

 

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,

See if this YouTube video helps - Date Presets in Power BI (youtube.com)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors