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
Anonymous
Not applicable

YTD ON selected FiscalPeriod

 

Hi, I am trying to do the below, If say user selects 2022001 & 2022005 in the filter list, I want my YTD to calculate all Amounts below (max(selectedValue(fiscalperiod). I tried DAX to do

Calculate(SUM (amount), Filter(FISCALPERIOD <= MAX(Selected(FiscalPeriod)) but this errors out saying I can't use in this context. 

 

Any pointers pls.. Thanks Krishna.

FISCALPERIODAMOUNT

2022001

100
2022002100
2022003100
2022004100
2022005100
2022006100
2022007100
2022008100
2022009100

  FILTERS

2022001
2022002
2022003
2022004
2022005
2022006
2022007
2022008
2022009
2022010
2 ACCEPTED SOLUTIONS

@Anonymous ,

 

You can use Year and period. But have them in separate table with Key Year Period to join back

 

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[period] <= Max('Date'[period]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[period] <= Max('Date'[period])))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

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

View solution in original post

v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

If your tables are like this:

vjianbolimsft_3-1657101830534.png

 

You can use the measure:

 

YTD =
VAR _max =
    MAXX ( ALLSELECTED ( 'Table'[FISCALPERIOD] ), [FISCALPERIOD] )
RETURN
    CALCULATE (
        SUM ( [AMOUNT] ),
        FILTER ( ALL ( 'Table' ), [FISCALPERIOD] <= _max )
    )

 

Final output:

vjianbolimsft_5-1657101869543.png

 

If it isn't your expected output, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

If your tables are like this:

vjianbolimsft_3-1657101830534.png

 

You can use the measure:

 

YTD =
VAR _max =
    MAXX ( ALLSELECTED ( 'Table'[FISCALPERIOD] ), [FISCALPERIOD] )
RETURN
    CALCULATE (
        SUM ( [AMOUNT] ),
        FILTER ( ALL ( 'Table' ), [FISCALPERIOD] <= _max )
    )

 

Final output:

vjianbolimsft_5-1657101869543.png

 

If it isn't your expected output, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

daXtreme
Solution Sage
Solution Sage

Hi @Anonymous 

 

To do YTD on a Fiscal Period you should also have a Fiscal Year field somewhere... If you don't, then you won't be able to know which Fiscal Year your period is in. Of course, you could do some ugly stunts on values like 2022001 to retrieve the year but this is not recommended and goes against the rules of good PBI/DAX design.

 

Also, we don't know if the two tables are joined. Depending on this, the DAX will be written differently.

Anonymous
Not applicable

Hi @daXtreme , thanks for responding. yes there is Fiscal year too as a field. But what Iam looking for is, like in sql you can filter by say 

select sum(amount) from table where fisacaperiod <= max(selected(fiscalperiod).

Thanks

 

I am looking ffor something like this  - as it is at aggregated level, it doesn't have a Date field (posting date etc.)

 

@Anonymous ,

 

You can use Year and period. But have them in separate table with Key Year Period to join back

 

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[period] <= Max('Date'[period]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[period] <= Max('Date'[period])))

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

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
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.