Forum Discussion

Steamedbunz's avatar
Steamedbunz
Frequent Visitor
1 year ago
Solved

Help with DAX Code, dynamically calculates the sum for the past 6 months.

I have this DAX code that caculates the sum of tiles for the latest 6 months period based on my facts data. However, I recently found out its doing the wrong calculations when I apply certain filter ...
  • danextian's avatar
    1 year ago

    Hi Steamedbunz 

     

    Those highlighted cells are blank because the max dates for those are only unitl October. Also, you cannot assign a value to a row that doesn't exist (eg., NSW and Nov-24). Instead use a separate dates table and create this measure:

    Last 6 Months Tiles = 
    CALCULATE (
        SUM ( 'Tiles Order Data'[Tiles] ),
        DATESINPERIOD ( DatesTable[Date], MAX (DatesTable[Date] ), -6, MONTH )
    )
    

    Notice that DATESINPERIOD is applied to DatesTable[Date] and not 'Tiles Order Data'[Date]

    Please see the attached pbix.