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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
ttansriw
Frequent Visitor

Calculate YTD based on measure

Hi All,

 I have 1 table  and the data like this

DateAttributeValueIndex
22/01/2021TR11001
23/01/2021TR11202
24/01/2021TR11303
26/01/2021TR11404
22/01/2021TR22001
23/01/2021TR22022
24/01/2021TR22033
26/01/2021TR22054

 

I calculate the difference via index by this formula

 

 

diff =
var _nextID = sum(tMain[Index]) +1

var _tr = SELECTEDVALUE(tMain[Attribute])

var _result =CALCULATE(
                    calculate(sum(tMain[Value]),
                    FILTER(all(tMain),tMain[Index] = _nextID),
                    tMain[Attribute]= _tr
) -
                   CALCULATE(
                   sum(tMain[Value]),
                   tMain[Attribute] =_tr
)
)

return
if(_result <0 ,0,_result)
 
and I got the output of what I want
 
ttansriw_1-1628652921851.png

 

---------------------------------------------------
Then I want to calculate YTD
 
 
diff YTD =  TOTALYTD([diff],tCalendar[Date])
 
This is the output
ttansriw_2-1628653207759.png

 

----------------------------------------
 
and this is what I want
ttansriw_4-1628653533421.png

 


I want to find YTD and MTD with the same attribute.

The result isn't going out. Do I need to fix the diff measure or anything else?
Anyone help me, please!! 
 
Thank you!

 

4 REPLIES 4
amitchandak
Super User
Super User

@ttansriw , Make sure you take Max for value.   and tCalendar is marked as date tbale and dates in the visual are used from tCalendar

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

@amitchandak 
I summarize all the data so all the data is maxed with the unique date in the main table

and marked as a date in a table calendar already.

The output appears like in the picture.

@ttansriw ,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

@amitchandak  here is the link

 

https://www.dropbox.com/s/7wm8wg58dq1xyjl/test.pbix?dl=0

 

I want to calculate the diff between rows by each attribute and then calculate ytd/mtd for each attribute.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors