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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

calculate value between two chosen filtered months

hi

 

i have a filter with 5 months values, lets say i have chosen 01.2022 and 03.2022.

i have an income column that contains income value for all dates within each month.

 

The problem:

i need to sum up income for all days in 01.2022 and 03.2022 and calculate the difference between the two months, i.e. income for max month - income for min month.

 

this should work with whatever 2 months i choose in the filter.

 

i have googled and couldn't find any solutions to this problem.

is this even possible?

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

H9 @Anonymous 
Please try

Difference =
VAR SelectedMonths =
    ALLSELECTED ( TableName[Month] )
VAR MaxMonth =
    MAXX ( SelectedMonths, TableName[Month] )
VAR MinMonth =
    MINX ( SelectedMonths, TableName[Month] )
VAR MaxValue =
    CALCULATE ( [Income], TableName[Month] = MaxMonth )
VAR MinValue =
    CALCULATE ( [Income], TableName[Month] = MinMonth )
RETURN
    MaxValue - MinValue

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

the reason why i have to use index for this is that i have missing months in between, so the previousmonth etc functions won't work

@Anonymous 
Yes, but what does that have to do with finding the two selected months? Gaps are irrelevant here.

Anonymous
Not applicable

that didn't work either 😞

 

what i have done so far which gets me a little on the way is the following:

Index = RANKX(Prognosemodell_Prognose_Total_Test_Historikk, Prognosemodell_Prognose_Total_Test_Historikk[prognose_dato], , ASC, Dense)
 
i.e. i have created an index for the month, which means the last month has the highest index and the oldest months have index 1.
 
then i used this to pick up the value for the highest index chosen - 1, i.e. i can see the difference between the highest chosen index and the next on the list.
 
inntekter forrige = CALCULATE (
    SUM ( Prognosemodell_Prognose_Total_Test_Historikk[Inntekter] ),
    FILTER (
        ALLEXCEPT ( Prognosemodell_Prognose_Total_Test_Historikk,date_dim[Date] ),
        Prognosemodell_Prognose_Total_Test_Historikk[Index]
            = MAX ( Prognosemodell_Prognose_Total_Test_Historikk[Index] ) - 1)           
    )
 
what would actually solve the problem is if i can set the -1 to the index of the min of the chosen months. any idea on how to do this?

Hi @Anonymous 
It depend on the filter context of the visual itself. I can see that all columns are from the same table. Not having dimention tables might be little tricky. The solution I have provided earlier (if the month column is a numeric value column) should work, however, depending on the existing filter context, the filter of some columns might have to be removed. Please provide more context in order to support you further. Thank you.

@Anonymous 

You can use Variables in the DAX Measures.
Helping Link: https://docs.microsoft.com/en-us/dax/best-practices/dax-variables

 

As communicated by @tamerj1 , you can cater this scenario.


Did I answer your question? Mark my post as a solution! Kudos are also appreciated!
 

tamerj1
Super User
Super User

H9 @Anonymous 
Please try

Difference =
VAR SelectedMonths =
    ALLSELECTED ( TableName[Month] )
VAR MaxMonth =
    MAXX ( SelectedMonths, TableName[Month] )
VAR MinMonth =
    MINX ( SelectedMonths, TableName[Month] )
VAR MaxValue =
    CALCULATE ( [Income], TableName[Month] = MaxMonth )
VAR MinValue =
    CALCULATE ( [Income], TableName[Month] = MinMonth )
RETURN
    MaxValue - MinValue
Anonymous
Not applicable

i can't see how that will solve my problem.

 

i have a table visual with month and total_income and difference.

 

it should look like the following:

BjornJorgensen_0-1661253618729.png

 

my problem is how to calculate the difference part, based on ANY chosen months in the filter.

bilalrana
Resolver I
Resolver I

Hi @Anonymous 

For this you can use the Date Filter to set Max Min Range of Dates. Follow the instructions from the link:

https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

 

Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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