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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
ladislaocsulak
Frequent Visitor

DAX Measure not affected by slicer

Hello,

I would appreciate help with the next problem.

I created the following measure because I need the quantity of sales for the last 30 days.

 

sales_quantity_last_30_days = CALCULATE(DISTINCTCOUNT(sales[id]),DATESINPERIOD ( Calendario[Date], TODAY(), -30, DAY ))

 

The problem is that I have a slicer to filter the dates that worked fine if I used if I looked at the quantity of total sales (not just the last 30 days). But when using the created measure, it is not affected by the slicer.

And I would like the slicer to affect the measure created so that it shows sales for the previous 30 days based on the last day filtered in the slicer.

 

I upload a dummy table where I show the situation of my measurements and how the slicer affects the measure counting the total sales and not the other that counts just the last 30 days:

https://drive.google.com/drive/folders/1TOYezhAuiy0ADTNcKVL1ayNw5XoLMo_I?usp=sharing

 

 

Thanks in advance!

1 ACCEPTED SOLUTION
djurecicK2
Super User
Super User

Hi @ladislaocsulak ,

 Please try replacing TODAY() with MAX(Calendario[Date])

 

 

View solution in original post

4 REPLIES 4
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @ladislaocsulak 

Can you pleas try the following:

Formula =
var __Today = TODAY()
var __StartDay = __Today - 30

Return

CALCULATE(
   DISTINCTCOUNT(sales[id]),
   DATESBETWEEN ( Calendario[Date], __StartDay, __Today)
)

 

It could be that you need to calculate -29 isntead of -30 depending on your logic

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

This keeps the measure in the same way, without being affected by the slicer.

djurecicK2
Super User
Super User

Hi @ladislaocsulak ,

 Please try replacing TODAY() with MAX(Calendario[Date])

 

 

This worked. Thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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