Forum Discussion

DC2024's avatar
DC2024
Frequent Visitor
2 years ago
Solved

Help with data shaping / data validation in Power BI Desktop

Hi,

 

First time posting on here, relatively new user to Power BI and am a little stuck on how to build what I want to build!

 

I have a data table with the below columns (simplified for the purposes of this example). The 'ID' is the "top-level" record, and for each ID there are sub-ID rows which have category A, B or C. Each of these sub-IDs make up a percentage of the "top-level" ID, all summing to 100%.

 

The table contains entire history of each ID's sub-ID records over time (via the Record Date column).

 

IDRecord Date (DD/MM/YYYY)Sub-IDCategoryPercentage of ID
100001/01/2024100A20%
100001/01/2024101A10%
100001/01/2024205A20%
100001/01/2024103B20%
100001/01/2024400B30%
100001/02/2024100A10%
100001/02/2024101A20%
100001/02/2024650C40%
100001/02/2024670C10%
100001/02/2024690C20%
100115/12/2023100A50%
100115/12/2023103B30%
100115/12/2023150B20%
100104/01/2024160B50%
100104/01/2024650C20%
100104/01/2024660C30%

 

What I'd like is to have a visual that can filter only for rows where, for each ID and record date:

- The 'Percentage of ID' column is >20% for an individual row, AND

- The summed 'Percentage of ID' column for that row's category is >50%.

 

In the above sample data, this would mean that only the row highlighted in red (ID 1000 / Sub-ID 650 / Record Date 01/02/2024) would pass the above criteria. That's because that row has weight >20% (40%), AND that sub-ID's category (Category C) for ID 1000 for that Record Date sums to 70%.

 

I've managed to create a calculated column to allow me to filter for any records that pass the first criteria, but am struggling to create a column or measure that will give me both. Everything I have tried so far only calculates at the row-level.

 

Apologies if this doesn't make sense - let me know if you need any more information!

 

Thank you

DC

  • Hi,

    Write these calculated column formulas

    Column = CALCULATE(SUM(Data[Percentage of ID]),FILTER(data,Data[ID]=EARLIER(Data[ID])&&Data[Record Date (DD/MM/YYYY)]=EARLIER(Data[Record Date (DD/MM/YYYY)])&&Data[Category]=EARLIER(Data[Category])))
    Column 2 = if(AND(Data[Percentage of ID]>0.2,Data[Column]>0.5),1,0)

    Hope this helps.

     

5 Replies

  • Hello DC2024,

     

    Can you please try this:

     

    1. Create a Measure for Row-Level Percentage Criteria (I know you've mentioned you've already done this, but including it for completeness)

    PercentageOver20 = IF(MAX('Table'[Percentage of ID]) > 0.2, 1, 0)
    

    2. Create a Measure for Category-Level Summed Percentage Criteria

    CategorySumOver50 = 
    CALCULATE(
        SUM('Table'[Percentage of ID]),
        ALLEXCEPT('Table', 'Table'[ID], 'Table'[Category], 'Table'[Record Date])
    ) > 0.5
    

    3. Combine the Criteria in a Single Measure

    ValidRows = 
    IF(
        [PercentageOver20] = 1 && [CategorySumOver50],
        1,
        0
    )
    
    • DC2024's avatar
      DC2024
      Frequent Visitor

      Thank you very much Sahir ! Really appreciate your time helping with this.

  • Hi,

    Write these calculated column formulas

    Column = CALCULATE(SUM(Data[Percentage of ID]),FILTER(data,Data[ID]=EARLIER(Data[ID])&&Data[Record Date (DD/MM/YYYY)]=EARLIER(Data[Record Date (DD/MM/YYYY)])&&Data[Category]=EARLIER(Data[Category])))
    Column 2 = if(AND(Data[Percentage of ID]>0.2,Data[Column]>0.5),1,0)

    Hope this helps.

     

    • DC2024's avatar
      DC2024
      Frequent Visitor

      Hi Ashish

       

      Thank you very much - this seems to have solved my issue! Thanks to you and Sahir for providing solution so quickly ğŸ˜Š