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
vandestra
Regular Visitor

compare different interval variables in time periods

I would like to compare for example the number of pupils this school year with the number of pupils the previous year in the previous class. For example: last  year, there were 100 pupils in 5th grade and 200 in 6th grade. This year, there are 105 in 6th grade - the difference is +5.  We call it the "flow through" rate. I have made a formula with dax formula sameperiodlastyear, so this shows that in 6th grade are 95 fewer pupils compared to last year, in a nice graph with data from 2009 to 2022, but I need to the graph to show differently. For example in the graph below. In 2022 it looks like a disaster in the "purple" school: a lot of pupils have left their grade. But in fact, the school has gained pupils compared to the previous year in the previous grade !

 

vandestra_1-1654153372284.png

 

1 ACCEPTED SOLUTION

Hi @vandestra ,

 

1. Please add the index column.

 

vkkfmsft_2-1654583008190.png

 

2. Use the Ctrl key to select both the Grade and Index columns, then unpivot the other columns.

 

vkkfmsft_0-1654582450025.pngvkkfmsft_1-1654582565437.png

 

3. Create the measure.

 

Diff = 
VAR LastGradeYear =
    CALCULATE (
        SUM ( 'Table'[Number] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index]
                = MAX ( 'Table'[Index] ) - 1
                && 'Table'[Year]
                    = MAX ( 'Table'[Year] ) - 1
        )
    )
RETURN
    IF ( LastGradeYear <> BLANK (), SUM ( 'Table'[Number] ) - LastGradeYear )

vkkfmsft_3-1654583145851.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

3 REPLIES 3
amitchandak
Super User
Super User

@vandestra ,

You need to have a change % measure

 

example , With help from a separate date table  

 

//Only year vs Year, not a level below

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

or

 

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

I need that there are two categories that are switched: date ànd grade. I will illustrate with an example.

suppose that these are the numbers of pupuls registered: (table with numbers is pasted at the end)

vandestra_0-1654166006911.png

Then I make a calculation: in the previous year and in the previous grade.

vandestra_1-1654166063248.png

Then one can notice on a graph that in the year 2021 something extraordinary happened for the pupils that went from the 4th grade to the 5th grade. 

vandestra_2-1654166160183.png

 

Grade201720182019202020212022
1st40107936130119
2nd8045112935531
3rd100784010710257
4th2094804911599
5th160258686100122
6th200164209592105

Hi @vandestra ,

 

1. Please add the index column.

 

vkkfmsft_2-1654583008190.png

 

2. Use the Ctrl key to select both the Grade and Index columns, then unpivot the other columns.

 

vkkfmsft_0-1654582450025.pngvkkfmsft_1-1654582565437.png

 

3. Create the measure.

 

Diff = 
VAR LastGradeYear =
    CALCULATE (
        SUM ( 'Table'[Number] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index]
                = MAX ( 'Table'[Index] ) - 1
                && 'Table'[Year]
                    = MAX ( 'Table'[Year] ) - 1
        )
    )
RETURN
    IF ( LastGradeYear <> BLANK (), SUM ( 'Table'[Number] ) - LastGradeYear )

vkkfmsft_3-1654583145851.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.