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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mrfsca
Frequent Visitor

YTD Measure Using Slicer Selection

Hi, I am doing a simple formula in excel where i wanna calculate order qty and target (both YTD) to put in a column and line chart. When I'm transforming it into PBI, I made 2 quick measure using TOTALYTD to calculate the tgt accum and order accum but when I create a measure to calculate the order or target YTD, i can't seem to figure it out how to call the max value like i did in my excel. I put 2 slicer in my report so i need to show the data according to the selected value. This following syntax doesnt work. Please advise me. Thank you in advance

 

% Target YTD =
var sg = SELECTEDVALUE('Table1'[Type])
var ds = SELECTEDVALUE('Table1'[Group])
Var _maxdata = CALCULATE(MAX('TableDate'[Date]), FILTER('Table1', 'Table1'[Type]=sg && 'Table1'[Group]=ds))
RETURN
CALCULATE(DIVIDE([Target YTD], _maxdata))



This is my dummy data

Target' Tgt Accum  order  Order Accum  order ytd  tgt ytd 
200             200             195             1958.13%8.33%
200             400             161             35614.83%16.67%
200             600             130             48620.25%25.00%
200             800             132             61825.75%33.33%
200        1,000             187             80533.54%41.67%
200        1,200             168             97340.54%50.00%
200        1,400             166        1,13947.46%58.33%
200        1,600             167        1,30654.42%66.67%
200        1,800             163        1,46961.21%75.00%
200        2,000             160        1,62967.88%83.33%
200        2,200             179        1,80875.33%91.67%
200        2,400             189        1,99783.21%100.00%
2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

I cannot understand your requirement.  Without a Date column, how can you complete YTD figures?  Review your data very well, repost something more meaningful and show the expected result.


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

hello @mrfsca 

 

please check if this accomodate your need.

Irwan_0-1729128818706.png

 

i assumed you good with accumulated value. but just incase, here are the DAX for both accumulated value.

Order Accum = 
var _Type = SELECTEDVALUE('Table'[Type])
var _Group = SELECTEDVALUE('Table'[Group])
var _Index = SELECTEDVALUE('Table'[Index])
Return
SUMX(
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Type]=_Type&&
        'Table'[Group]=_Group&&
        'Table'[Index]<=_Index
    ),
    'Table'[ order ]
)
TGT Accum = 
var _Type = SELECTEDVALUE('Table'[Type])
var _Group = SELECTEDVALUE('Table'[Group])
var _Index = SELECTEDVALUE('Table'[Index])
Return
SUMX(
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Type]=_Type&&
        'Table'[Group]=_Group&&
        'Table'[Index]<=_Index
    ),
    'Table'[Target']
)

 

Here is the DAX for percent Order YTD.

Order YTD = 
DIVIDE(
    [Order Accum],
    MAXX(
        ALLSELECTED('Table'),
        [Order Accum]
    )
)
for TGT YTD, the DAX is exactly same but different expression (use "target" instead of "Order")
TGT YTD = 
DIVIDE(
    [TGT Accum],
    MAXX(
        ALLSELECTED('Table'),
        [TGT Accum]
    )
)

 

also, dont mind the index column, i used it for ordering but i assumed you have another column for indexing since you have done the accumulated value calculation.

 

Hope this will help.

Thank you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.