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
darylmc
Frequent Visitor

Measure showing zero when not filtered

I'm looking to show a measure to the same week in the previous fiscal year:

 

 

LY Stock (sgls) = 
VAR currentFiscalYear =
    MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
    MAX ( 'Stock & Sales'[fiscal_week_number] )

RETURN
    CALCULATE (
        Sum('Stock & Sales'[stock_sgls]), ALLSELECTED('Stock & Sales'[bu]),
        FILTER (
            ALL ( 'Stock & Sales' ),
            'Stock & Sales'[fiscal_year]
                = currentFiscalYear - 1
                && 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek 
    ),FILTER (
            ALL ( 'Stock & Sales' ),'Stock & Sales'[bu] = SELECTEDVALUE( ( 'Stock & Sales'[bu] ))))

 

 

However, when it's not filtered, it shows zero. I need it to show the total.

 

Can someone help, please?

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Please try this expression instead.  Not sure why you have the ALLSELECTED() in there and then filter it back down again with SELECTEDVALUE.  In any case, the SELECTEDVALUE is why you were not seeing anything for total.  I replaced it with VALUES.  Also note that I updated your ALL to only include the columns being filtered (a good practice).

 

LY Stock (sgls) =
VAR currentFiscalYear =
    MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
    MAX ( 'Stock & Sales'[fiscal_week_number] )
RETURN
    CALCULATE (
        SUM ( 'Stock & Sales'[stock_sgls] ),
        ALLSELECTED ( 'Stock & Sales'[bu] ),
        FILTER (
            ALL (
                'Stock & Sales'[fiscal_year],
                'Stock & Sales'[fiscal_week_number]
            ),
            'Stock & Sales'[fiscal_year] = currentFiscalYear - 1
                && 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek
        ),
        VALUES ( 'Stock & Sales'[bu] )
    )

Regards,

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
darylmc
Frequent Visitor

Excellent! Thank you.

 

Noted on the ALL requirement. 

mahoneypat
Employee
Employee

Please try this expression instead.  Not sure why you have the ALLSELECTED() in there and then filter it back down again with SELECTEDVALUE.  In any case, the SELECTEDVALUE is why you were not seeing anything for total.  I replaced it with VALUES.  Also note that I updated your ALL to only include the columns being filtered (a good practice).

 

LY Stock (sgls) =
VAR currentFiscalYear =
    MAX ( 'Stock & Sales'[fiscal_year] )
VAR currentFiscalWeek =
    MAX ( 'Stock & Sales'[fiscal_week_number] )
RETURN
    CALCULATE (
        SUM ( 'Stock & Sales'[stock_sgls] ),
        ALLSELECTED ( 'Stock & Sales'[bu] ),
        FILTER (
            ALL (
                'Stock & Sales'[fiscal_year],
                'Stock & Sales'[fiscal_week_number]
            ),
            'Stock & Sales'[fiscal_year] = currentFiscalYear - 1
                && 'Stock & Sales'[fiscal_week_number] = currentFiscalWeek
        ),
        VALUES ( 'Stock & Sales'[bu] )
    )

Regards,

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

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.