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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Calculate on the same sheet with two year filters.

Hello.

I have a table in which I use some measures to realize the total, difference and variation between two years. When using DAX measures the annuities passed them as a fixed value in each of the calculations, I would like to be able to select the year for one column and independently the year for another and perform the calculations.

I put a screenshot and try to explain myself better:

1bi.png

In this table where you put Total19 and Total20, I calculate them as follows:

Total19 - CALCULATE([Total], DATA[ANNUALITY]- 2019)+0
Total20 - CALCULATE([Total], DATA[ANNUALITY]- 2020)+0
I would like those totals to take them depending on the year I took for each of the two columns, and to automatically perform the calculation of variation and difference
Variation - Total20 - Total19
Var - DIVIDE([Variation], [Total19])+0
The idea would be to look like this, to select two years:

2bi.png

All the data I have in the same table, I have an annuity field, I also have in that table a date field (DDMMAAAA).

Greetings and thanks.

2 ACCEPTED SOLUTIONS
v-yingjl
Community Support
Community Support

Don't @Syndicate_Admin,

You must extract the year column as a seprate table:

Year table = DISTINCT('Table'[Year])

Create measures like this:

Total1 = SUM('Table'[value])

Total2 =
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Year] = SELECTEDVALUE ( 'Year table'[Year] )
            && 'Table'[Category] IN DISTINCT ( 'Table'[Category] )
    )
)

Diff = [Total2] - [Total1]

re.png

Attached to a sample file in the following, you hope it could help.

Best regards
Community Support Team _ Yingjie Li
If this post helps,then consider Accepting it as the solution to help other members find it faster.

View solution in original post

Fixed I created one more line in the filter and it already does what I need.

Greetings.

View solution in original post

5 REPLIES 5
v-yingjl
Community Support
Community Support

Don't @Syndicate_Admin,

You must extract the year column as a seprate table:

Year table = DISTINCT('Table'[Year])

Create measures like this:

Total1 = SUM('Table'[value])

Total2 =
CALCULATE (
    SUM ( 'Table'[value] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Year] = SELECTEDVALUE ( 'Year table'[Year] )
            && 'Table'[Category] IN DISTINCT ( 'Table'[Category] )
    )
)

Diff = [Total2] - [Total1]

re.png

Attached to a sample file in the following, you hope it could help.

Best regards
Community Support Team _ Yingjie Li
If this post helps,then consider Accepting it as the solution to help other members find it faster.

Hello, this served me, starting from your example I have a problem, I need you to filter through a city field, total1 does it correctly, but the total2 does not, the city is the same for the two totals, would you have to add another filter in the formula?

Fixed I created one more line in the filter and it already does what I need.

Greetings.

Hello, thank you very much for the solution, as that is what I need, it is giving me problems the data that shows me, but it is a matter of reviewing the example that you have provided me.

Greetings.

amitchandak
Super User
Super User

@Syndicate_Admin , not very clear. refer this blog does it for two date ranges. Seem like you need for two years

 

https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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