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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors