Forum Discussion

Hemant_Jaiswar's avatar
1 year ago

aggregation at customer name level

desired output 

Month Total 2023 Total 2024 LFL 2023 LFL 2024

Jan20352027
Feb21312122
Mar20372028
Apr32331233

Goal:

  1. Total 2023: Sum the sales for 2023 for each month.
  2. Total 2024: Sum the sales for 2024 for each month.
  3. LFL 2023: For each month, calculate the total 2023 sales only for stores that have sales in both 2023 and 2024 for that same month.
  4. LFL 2024: For each month, calculate the total 2024 sales only for stores that have sales in both 2023 and 2024 for that same month.


data

Month Store 2023 Sales 2024 Sales

JanS231012
JanS241015
JanS25(blank)8
FebS231211
FebS24911
FebS25(blank)9
MarS23(blank)9
MarS241518
MarS25510
AprS2320(blank)
AprS24221
AprS251012

4 Replies

  • Hemant_Jaiswar 

    Use the following DAX measures:

    Total 2023 = SUM('Table'[2023 Sales])

    Total 2024 = SUM('Table'[2024 Sales])
    LFL 2023 = 
    CALCULATE(
    SUM('Table'[2023 Sales]),
    FILTER(
    'Table',
    NOT(ISBLANK('Table'[2023 Sales])) &&
    NOT(ISBLANK('Table'[2024 Sales]))
    )
    )
    LFL 2024 = 
    CALCULATE(
    SUM('Table'[2024 Sales]),
    FILTER(
    'Table',
    NOT(ISBLANK('Table'[2023 Sales])) &&
    NOT(ISBLANK('Table'[2024 Sales]))
    )
    )

    Create a table visual with Month as rows and the four measures as columns.

  • no 

    • LFL 2023: For each month, calculate the total 2023 sales only for stores that have sales in both 2023 and 2024 for that same month.
    • LFL 2024: For each month, calculate the total 2024 sales only for stores that have sales in both 2023 and 2024 for that same month.
      and in my output there is only month dimension

      Month Total 2023 Total 2024 LFL 2023 LFL 2024

      Jan20352027
      Feb21312122
      Mar20372028
      Apr32331233

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Hemant_Jaiswar ,

     

    I want to acknowledge valuable input provided by Kedar_Pande  . Their initial ideas help guide my approach. However, I noticed that more details are needed to fully understand this issue.

    (1) Create a column.

    Flag = IF([2023 Sales]<>BLANK() && [2024 Sales]<> BLANK(),1,0) 

    (2) Then create a new table.

    Table 2 = 
    ADDCOLUMNS (
        VALUES ( 'Table'[Month] ),
        "Total 2023",
            CALCULATE (
                SUM ( 'Table'[2023 Sales] ),
                FILTER ( 'Table', 'Table'[Month] = EARLIER ( 'Table'[Month] ) )
            ),
        "Total 2024",
            CALCULATE (
                SUM ( 'Table'[2024 Sales] ),
                FILTER ( 'Table', 'Table'[Month] = EARLIER ( 'Table'[Month] ) )
            ),
        "LFL 2023",
            CALCULATE (
                SUM ( 'Table'[2023 Sales] ),
                FILTER ( 'Table', [Flag] = 1 && 'Table'[Month] = EARLIER ( 'Table'[Month] ) )
            ),
        "LFL 2024",
            CALCULATE (
                SUM ( 'Table'[2024 Sales] ),
                FILTER ( 'Table', [Flag] = 1 && 'Table'[Month] = EARLIER ( 'Table'[Month] ) )
            )
    )

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.