Forum Discussion

nok's avatar
nok
Icon for Advocate II rankAdvocate II
11 months ago
Solved

Create a table with unique IDs and calculations based on the original table

Hi!

I have a table that follows this structure:

IDBalance   Type   Date
111   10A20/10/2025  
11120M30/10/2025
2225A02/12/2025
2223B01/09/2024
33340M23/11/2024
33330M27/05/2025
33321A21/09/2025
4449B17/03/2025

 

I want to create a new calculated table based on the original that displays distinct IDs, sum of Balance for each ID, columns with the count of rows for each type, and the maximum date for each ID and type.
The end result would be a table like this:

IDBalance  Count
(Type A)   
Max Date
(Type A)
Count
(Type B)   
Max Date
(Type B)
Count
(Type M)   
Max Date
(Type M)
111   30120/10/2025          0 130/10/2025   
2228102/12/2025101/09/2024    0 
33371121/09/20250 227/05/2025
44490 117/03/20250 


How can I do this?

  • Hey,

    try to make a calculated table with this dax

     

    SummaryByID :=
    ADDCOLUMNS(
        SUMMARIZE(
            'Fact',
            'Fact'[ID],
            "Balance", CALCULATE(SUM('Fact'[Balance]))
        ),
        // Type A
        "Count (Type A)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "A"),
        "Max Date (Type A)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "A"),
        // Type B
        "Count (Type B)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "B"),
        "Max Date (Type B)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "B"),
        // Type M
        "Count (Type M)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "M"),
        "Max Date (Type M)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "M")
    )

2 Replies

  • Hey,

    try to make a calculated table with this dax

     

    SummaryByID :=
    ADDCOLUMNS(
        SUMMARIZE(
            'Fact',
            'Fact'[ID],
            "Balance", CALCULATE(SUM('Fact'[Balance]))
        ),
        // Type A
        "Count (Type A)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "A"),
        "Max Date (Type A)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "A"),
        // Type B
        "Count (Type B)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "B"),
        "Max Date (Type B)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "B"),
        // Type M
        "Count (Type M)",     CALCULATE(COUNTROWS('Fact'), 'Fact'[Type] = "M"),
        "Max Date (Type M)",  CALCULATE(MAX('Fact'[Date]), 'Fact'[Type] = "M")
    )
  • Hi,

    If you are OK with a measure based solution, then write these measures

    Total = sum(Data[Balance])

    C = calculate(countrows(Data),data[type]="A")

    D = max(Data[Date])

    Hope this helps.