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
powerbi-help1
New Member

ALL Filter is causing column subtotal value to be incorrect

The following formula is pulling the correct value in the matrix but the column subtotal of the row is incorrect and only totaling the last value in the matrix row.

 

CALCULATE([Gross_Amount], FILTER(ALL(Periods), Periods[Index] = MAX(Periods[Index])-13))

 

The intentioion of the formula is have the current year period column headings ignored and then pull the previous year figures for the same period of time. IE P05 2021 ignored, data for P05 2020 pulled instead.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

 

[Measure] =
var VisiblePeriods = DISTINCT( Periods[Index] )
var PeriodsBack = 
    FILTER(
        ALL( Periods[Index] ),
        ( Periods[Index] + 13 ) in VisiblePeriods
    )
var Result = 
    CALCULATE(
        [Gross_Amount],
        PeriodsBack,
        // Depending on what you really want
        // your measure to do, you can include
        // this line below or exclude it:
        ALL( Periods )
    )
return
    Result

 

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

 

 

[Measure] =
var VisiblePeriods = DISTINCT( Periods[Index] )
var PeriodsBack = 
    FILTER(
        ALL( Periods[Index] ),
        ( Periods[Index] + 13 ) in VisiblePeriods
    )
var Result = 
    CALCULATE(
        [Gross_Amount],
        PeriodsBack,
        // Depending on what you really want
        // your measure to do, you can include
        // this line below or exclude it:
        ALL( Periods )
    )
return
    Result

 

 

I have made some additional changes to the formula, please see below.

 

var VisiblePeriods = DISTINCT( Periods[Index] )
var PeriodsBack =
FILTER(ALL(Periods),MAX(Periods[Index])-13 in VisiblePeriods)
var Result =
CALCULATE([Gross_Amount],PeriodsBack)
return
Result

 

This returns a zero value but no error, any advice on how to solve?

 

Thank you. 

Anonymous
Not applicable

There was a missing comma after PeriodsBack. I've corrected it above. Apart from this the formula works correctly when the model is set up the way I think it is. Since you have not shown the model... I had to imagine what it is. I can easily demonstrate that it does what it should.

Thank you, yes i was able utilize the formula to to produce the results as needed. 

Anonymous
Not applicable

Great 🙂

Thank you for the response. The formula did not work and returned a 0 value (after being edited to not have an error).

When I tried to use the result portion above as written and removed the //lines keeping the ALL (Periods) there was an error:

 

"The syntax for 'ALL' is incorrect. (DAX(var VisiblePeriods = DISTINCT( Periods[Index] )var PeriodsBack = FILTER( ALL( Periods[Index] ), ( Periods[Index] + 13 ) in VisiblePeriods )var Result = CALCULATE( [Gross_Amount], PeriodsBack ALL( Periods ) )return Result))."

 

Formula written as that produced error:

var VisiblePeriods = DISTINCT( Periods[Index] )
var PeriodsBack =
FILTER(
ALL( Periods[Index] ),
( Periods[Index] + 13 ) in VisiblePeriods
)
var Result =
CALCULATE(
[Gross_Amount],
PeriodsBack
ALL( Periods )
)
return
Result

 

Essentially I need the matrix to ignore the Year-Period columns and index from the CY period (ie P05 2021) to PY (P05 2020, hence the -13 on the index formula). My original formula I sent pulls each period but does not subtotal properly. 

 

 

Thank you.

 

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