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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Padagon
Regular Visitor

Combine Measure to filter by conditions

Hi everybody, hope you're doing great

 

I need some advise to solve an issue.

 

I have the next information (a sample), this is a table that keeps growing over time

 

MonthYearNameSegmentRegionIncomeCostExpensesForecast
12022AAASeg1North1001010150
22022BBBSeg2Center2002020150
32022CCCSeg1South3003030150
12023AAASeg1North4004040150
22023BBBSeg2Center5005050150
32023CCCSeg1South6006060150
12024AAASeg1North7007070150
22024BBBSeg2Center8008989150
32024CCCSeg1South90090901 50

 

Of course, for this sample numbers are random (and nonsense here)

 

As you can see, I have  certain names that belong to Segment 1, others to Segment 2, and so on.., but that doesn't mean that Seg1 belongs to same Region, although I could have more names that belong to Seg1 and North region

 

What I would like to do, is to create a Calculated Measure, actually many calculated measures, that calculates the change income between Years, but I also need to add the condition to select those years.

 

What do I mean?

Suppose I name the calculated measure Income Change. The calculated measure should calculate the Income between a Year I select by using a filter, and give the income with the previous year so, if in a filter (or selection) I choose Y2023 it should select Y2022 automatically to do  Income Change = (Income in Y2023 - Income in Y2022)/ Income in Y2022 . Then if I choose on the filter Y2024 then it should do Income Change = (Income in Y2024 - Income in Y2023)/ Income in Y2023 . Or select those 2 years and apply them to the Calculated Measure.  I know that using some filters for Name, Region, Segment the calculated measure will do the magic to do the desired results when considering them. But what I need to do is to choose some how the 2 values (Year and PreviousYear) to automatically do the change in the calculated measure.  Also, I need to consider the month, because I need to compare the Income for the same month in 2 different years. 

 

The same thing I'll need to do with change in Expenses and change in Forecast, but once I have one I know I could do the rest.

 

Thanks.

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Padagon ,

Oh sorry, I thought you were talking about the previous year just as an example, and assumed that any earlier years would be covered as well😂.
Just change the DAX into this:

Income Change = 
VAR _Year = SELECTEDVALUE(SlicerYear[Year])
VAR _PreviousYear = _Year - 1
VAR _Income_Year = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _Year && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
VAR _Income_PreviousYear = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _PreviousYear && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
RETURN
_Income_Year - _Income_PreviousYear

Just change here:

VAR _PreviousYear = _Year - 1

And the final output is as below:

vjunyantmsft_0-1720578999592.png

(900+800+700) - (600+500+400) = 900

Best Regards,
Dino Tao
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
v-junyant-msft
Community Support
Community Support

Hi @Padagon ,

Since you need to select two years (this year and previous year), in order to eliminate the mutual filtering effect, I suggest you add two new tables as slicers without any relationships:

vjunyantmsft_0-1720493451537.png

vjunyantmsft_1-1720493457565.png

vjunyantmsft_2-1720493529367.png

Then use this DAX to create a measure:

Income Change = 
VAR _Year = SELECTEDVALUE(SlicerYear[Year])
VAR _PreviousYear = SELECTEDVALUE(SlicerPreviousYear[PreviousYear])
VAR _Income_Year = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _Year && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
VAR _Income_PreviousYear = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _PreviousYear && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
RETURN
_Income_Year - _Income_PreviousYear

And the final output is as below:

vjunyantmsft_3-1720493746491.png

In my case, the Year and Previous Year slicers were created using the newly created table, and the other slicers used columns from the original table.

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

I can see what you did, but it not what I want, as I already tried it. I don't want to use 2 filters on de dashboard, that wouldn't be practical. I would like to select only one year, and get the calculations of the previous year automatically by using that measure.

 

I am not sure if this is possible.

 

Thanks for your answer though.

Hi @Padagon ,

Oh sorry, I thought you were talking about the previous year just as an example, and assumed that any earlier years would be covered as well😂.
Just change the DAX into this:

Income Change = 
VAR _Year = SELECTEDVALUE(SlicerYear[Year])
VAR _PreviousYear = _Year - 1
VAR _Income_Year = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _Year && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
VAR _Income_PreviousYear = 
CALCULATE(
    SUM('Table'[Income]),
    FILTER(
        ALL('Table'),
        'Table'[Year] = _PreviousYear && 'Table'[Month] IN VALUES('Table'[Month]) && 'Table'[Name] IN VALUES('Table'[Name]) && 'Table'[Segment] IN VALUES('Table'[Segment]) && 'Table'[Segment] IN VALUES('Table'[Segment])
    )
)
RETURN
_Income_Year - _Income_PreviousYear

Just change here:

VAR _PreviousYear = _Year - 1

And the final output is as below:

vjunyantmsft_0-1720578999592.png

(900+800+700) - (600+500+400) = 900

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

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors