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

Last 4 week gross margin formula not working

Hi all,

 

The below formula is not giving desired output

Average Gross Margin Last Four Weeks Filter = CALCULATE(
                                  [Total Gross Margin Level 2],
                                      FILTER(ALL(PBIDateTable[Week number]),
       PBIDateTable[Week number] <= MAX(PBIDateTable[Week number])-1
    && PBIDateTable[Week number] >= MAX(PBIDateTable[Week number])-4))/4

 

 

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

I think max function may break by all function , maybe you can try to use variable function:

 

Average Gross Margin Last Four Weeks Filter =
VAR _current =
    MAX ( PBIDateTable[Week number] )
RETURN
    CALCULATE (
        [Total Gross Margin Level 2],
        FILTER (
            ALL ( PBIDateTable ),
            PBIDateTable[Week number]
                <= _current - 1
                && PBIDateTable[Week number]
                >= _current - 4
        )
    )
        / 4

If above not help, please share some sample data for test.

 

 

Regards,

Xiaoxin Sheng

 

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

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.