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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Memphis28
Frequent Visitor

Percentage difference between dynamic date range

Afternoon

I have had a look on the forum and, depsite the wealth of knoweldge i can't seem to find the answer to my issue so hoping someone can point me in the right direction.

I think it is a simple ask but i am relatively new and can't seem to get my head around it.

 

I want to create a measure that will calculate the percentage difference between two values (this will be a total count value of cases/tickets). I want to be be able to change the date range using a slicer and have the percentage dynamically change wiht it.

 

So case count on the MIN date is first value and the case count on the MAX date is the second value. I tried using the quick measures tool but it forces your hand in to choosing a specific date as you can see below. Is there a way to adapt to function code to make it dynamic?

 

The outcome being two things, a scorecard that shows the percentage difference between the date range (as selcetd by a slicer) and a table with the date of each report and the difference between the MIN date and the date of the report (see bottom screen shot)

 

I am keen to learn so any guidance on how to do it but also why it is done that way is hugely appreciated.

 

Memphis28_0-1706099746626.png

 

 

Count of CASE_ID % difference from 27 October 2023 =
VAR __BASELINE_VALUE =
    CALCULATE(
        COUNTA('TeamJ'[CASE_ID]),
        'TeamJ'[Date of Report] IN { DATE(2023, 10, 27) }
    )
VAR __MEASURE_VALUE = COUNTA('TeamJ'[CASE_ID])
RETURN
    IF(
        NOT ISBLANK(__MEASURE_VALUE),
        DIVIDE(__MEASURE_VALUE - __BASELINE_VALUE, __BASELINE_VALUE)
    )
 
 
Below is showing the differnece from the 27th of Oct no matter the date selected using the slicer.
FYI the slicer uses the date of the report data
Memphis28_1-1706100220797.png

 

4 REPLIES 4
Memphis28
Frequent Visitor

Afternoon
I haven't had chances to try this suggestion yet, i will do as soon as i can and report back.
I did figure a quick and dirty way of getting some of what i needed but it isn't the final solution. I created two measures, one that found the Value on the FIRSTDATE in the Date table and one that found the LASTDATE in the date table and then wrote a 3rd measure to DIVIDE the two. Not elegent or efficient but it worked on the day.

Memphis28_0-1706530420868.png

 



PercentSlicerDiffMin = CALCULATE(COUNTA(TeamJ[CASE_ID]), FIRSTDATE(TeamJ[Date of Report]))

 

PercentSlicerDiffMin = CALCULATE(COUNTA(TeamJ[CASE_ID]), LASTDATE(TeamJ[Date of Report]))

PercentDivide = DIVIDE([PercentSlicerDiffMin]-[PercentSlicerDiffMax],[PercentSlicerDiffMax],0)
 
 
I still need a better solution that wll show the changes in a table so i will try and pull some sample data and a streamlined version of PBIX later today and share with you.
Again, the help is appreciated. Thank you
Anonymous
Not applicable

Hi @Memphis28 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1706148329295.png

(2) We can create a Date Slicer table and a measure.

Date Slicer = CALENDAR(FIRSTDATE('TeamJ'[date]),LASTDATE('TeamJ'[date]))
Measure = 
var _slicer_min_date=MIN('Date Slicer'[Date])
var _slicer_max_date=MAX('Date Slicer'[Date])
var _min_value=CALCULATE(COUNTA('TeamJ'[case_id]),FILTER(ALLSELECTED('TeamJ'),'TeamJ'[date]=_slicer_min_date))
var _max_value=CALCULATE(COUNTA('TeamJ'[case_id]),FILTER(ALLSELECTED('TeamJ'),'TeamJ'[date]=_slicer_max_date))
RETURN DIVIDE(_min_value,_max_value,0)

The range of the slicer at this point is 2023-2-1 through 2024-1-15, at which point the measure will count the number of cases on the minimum date (2023-2-1) / the number of cases on the maximum date (2024-1-15).

vtangjiemsft_2-1706148655993.png

If you change the slicer range, then the measure will also change automatically.

vtangjiemsft_3-1706148676139.png

(3) Then we can create another measure.

Measure 2 = 
var _slicer_min_date=MIN('Date Slicer'[Date])
var _min_value=CALCULATE(COUNTA('TeamJ'[case_id]),FILTER(ALLSELECTED('TeamJ'),'TeamJ'[date]=_slicer_min_date))
var _report_value=COUNTA('TeamJ'[case_id])
RETURN DIVIDE(_min_value,_report_value,0)

vtangjiemsft_4-1706148804365.png

For learning about measure values and dax, you can refer to the:

Measures in Power BI Desktop - Power BI | Microsoft Learn

Learn DAX basics in Power BI Desktop - Power BI | Microsoft Learn

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Thank you for the resolution, i have worked through it and as far as my powerbi DAX knowledge goes, nothing seems to be incorrect however i am get a BLANK value on the scorecard and the second measure produces no results in a table or matrix.

I have broken down each part of the measure you wrote and understand each bit indiviudally and it all makes perfect sense. Not only that PowerBi hasn't highlighted any issues. I tried doing it without the Date slicer and instead just used the date of the report directly but this gave me the same result. Next i removed any other slicers to see if that was impacting the data but again i got the same BLANK card.

Could something else in the report be interfering with the outcome other than another slicer?

Again, having broken down the measure in to its constituent parts it should, work but for no obvious reason, it isn't. Any other steer or guidance whould be hugely appreciated.

 

Thanks
Memphis

Anonymous
Not applicable

Hi @Memphis28 ,

 

Can you check the model relationship? Please make sure that there is no relationship between the slicer table and the data table.

vtangjiemsft_0-1706258707254.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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