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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Puja
Helper III
Helper III

Calculate measure dynamically with selected Slicer date

Hi Experts , 

I need some help .

 

I am able to do the static date calculation in the below final measure .

Puja_0-1662130705134.png

 

But my user wants date calculation dynamically.

 

EX: If the user chose 2023 09 on the slicer he should see data like in the the below Screenshot

Puja_1-1662130852441.png

Test Data

YearMonthYearMonthNumberActualforecastFinal
2022 820220814820197518264518263.7
2022 9202209109982122880413628804136
2022 10202210859750086279758627975
2022 11202211419390742044424204442
2022 12202212250155125362612536261
2023 120230180231561011813010118130
2023 2202302734159274888667488866
2023 3202303533373353901685390168
2023 4202304446992545694014569401
2023 5202305326093332537363253736
2023 6202306164747916309041630904
2023 720230772412524523867241252
2023 82023081052658348010110526583
2023 920230988424474525518842447
2023 1020231079993776021187999377
2023 1120231152454066315615245406
2023 1220231229146024326332914602

 

Thank you in advance :).

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Puja ,

 

I suggest you to inactive or remove the relationship between your fact table and dimdate table.

Here I create an unrelated dimdate table by dax.

DimDate = 
ADDCOLUMNS( CALENDAR(DATE(2022,01,01),DATE(2023,12,31)),"YearMonthNumber",YEAR([Date])*100+MONTH([Date]))

Add a [YearMonthNumber] column in fact table.

Then try this code to create the final measure.

M_Final = 
VAR _SELECTVALUE = SELECTEDVALUE(DimDate[YearMonthNumber])
VAR _ACTUAL = CALCULATE([Actual],FILTER(Test, Test[YearMonthNumber]>=_SELECTVALUE))
VAR _RESULT = CALCULATE(IF(_ACTUAL = BLANK(),[forecast],_ACTUAL))
RETURN
_RESULT

Result is as below.

RicoZhou_0-1662451687877.png

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi @Puja ,

 

I suggest you to inactive or remove the relationship between your fact table and dimdate table.

Here I create an unrelated dimdate table by dax.

DimDate = 
ADDCOLUMNS( CALENDAR(DATE(2022,01,01),DATE(2023,12,31)),"YearMonthNumber",YEAR([Date])*100+MONTH([Date]))

Add a [YearMonthNumber] column in fact table.

Then try this code to create the final measure.

M_Final = 
VAR _SELECTVALUE = SELECTEDVALUE(DimDate[YearMonthNumber])
VAR _ACTUAL = CALCULATE([Actual],FILTER(Test, Test[YearMonthNumber]>=_SELECTVALUE))
VAR _RESULT = CALCULATE(IF(_ACTUAL = BLANK(),[forecast],_ACTUAL))
RETURN
_RESULT

Result is as below.

RicoZhou_0-1662451687877.png

Best Regards,
Rico Zhou

 

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

Hi @Anonymous 

The measure is working as expected but is not adding the total correctly. I used SUMX, HASONEVALUE, ISINSCOPE to correct the totals but none is woorking for me.

 

Hope you can help me :).

Thanks much.

Thank you @Anonymous .

ribisht17
Super User
Super User

Hi @Puja ,

 

See if it helps, https://www.youtube.com/watch?v=3RcRqp_xgAw

 

Thanks,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin | PL 300 Certification Series 
amitchandak
Super User
Super User

@Puja , The slicer of year month should come from an independent date table

 

example, you can build you measure based on this


//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Year Month])
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Year Month] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.