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
dkarl403
New Member

Calculate percentage of revenue based on year and month from hierarchy picker with multichoice

I want to calculate the percentage of revenue for the picked year/years AND month/months that the user have picked, My DAX formula is the following:

 

YEAR.PNGMonth.PNG

 

 

 

 

 

 

 

Revenue = IF (
    SELECTEDVALUE ('Month'[Month]) > 1;
    CALCULATE (
    SUM ( MFE_RR_Generell_VerTrans[Revenue] );
        FILTER ( ALL ( MFE_RR_Generell_VerTrans ); MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101 && MFE_RR_Generell_VerTrans[DateMonth] = 'Month' && MFE_RR_Generell_VerTrans[DateYear] = SELECTEDVALUE ('Year'[Year]))
)
)

 

I know that this solution is not the correct one, but I dont know what else to try, this one (for obvious reasons) only works when you have picked ONE year AND one month. When i select multiple months the revenue wont calculate at all.

1 ACCEPTED SOLUTION

I had to modify my solution in order to get it to work even if none where selected, know I could have used ALLEXCEPT, but this works fine. Here is the full code:

 

OmsättningMFEUtfall = IF(COUNTROWS ( ALLSELECTED ( 'År'[År] )) = 8; CALCULATE (
    SUM ( MFE_RR_Generell_VerTrans[Utfall] );
            FILTER ( ALL ( MFE_RR_Generell_VerTrans ); MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101 )
); CALCULATE (
    SUM ( MFE_RR_Generell_VerTrans[Utfall] );
            FILTER (ALLSELECTED ( MFE_RR_Generell_VerTrans ); MFE_RR_Generell_VerTrans[DatumAr] IN ALLSELECTED ( 'År'[År] ) && MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101)
))
 

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @dkarl403,

 

AFAIK, selectedvalue function not support deal with multiple selection(it will return blank if select multiple items), please use allselected or values with countrows function to instead.

 

Sample:

 

Revenue =
IF (
    COUNTROWS ( ALLSELECTED ( 'Month'[Month] ) ) > 1;
    CALCULATE (
        SUM ( MFE_RR_Generell_VerTrans[Revenue] );
        FILTER (
            ALL ( MFE_RR_Generell_VerTrans );
            MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101
                && MFE_RR_Generell_VerTrans[DateMonth] IN ALLSELECTED ( 'Month'[Month] )
                && MFE_RR_Generell_VerTrans[DateYear] IN ALLSELECTED ( 'Year'[Year] )
        )
    )
)

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I had to modify my solution in order to get it to work even if none where selected, know I could have used ALLEXCEPT, but this works fine. Here is the full code:

 

OmsättningMFEUtfall = IF(COUNTROWS ( ALLSELECTED ( 'År'[År] )) = 8; CALCULATE (
    SUM ( MFE_RR_Generell_VerTrans[Utfall] );
            FILTER ( ALL ( MFE_RR_Generell_VerTrans ); MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101 )
); CALCULATE (
    SUM ( MFE_RR_Generell_VerTrans[Utfall] );
            FILTER (ALLSELECTED ( MFE_RR_Generell_VerTrans ); MFE_RR_Generell_VerTrans[DatumAr] IN ALLSELECTED ( 'År'[År] ) && MFE_RR_Generell_VerTrans[RRKontoGruppID] = 101)
))
 

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.