Forum Discussion
True Unduplicated
Hi TuckRhodes ,
Thank you for the detailed explanation!
You need to have an Index column to identify the first time the ID appears, like this:
Considering you mentioned that your data is huge, I would recommend doing this in Power Query to prevent possible performance and memory issues:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYMMVTSUQr28HcNBtKGSrE6CEF/Z2+QoBFM0Ais0jMoBEgbIwsGOPqFgFSaIGtHEowFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CATEGORY = _t, ITEM = _t, ID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CATEGORY", type text}, {"ITEM", type text}, {"ID", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type)}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"CATEGORY", "ITEM", "Index"}, {"CATEGORY", "ITEM", "Index"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Count",{{"Index", Int64.Type}})
in
#"Changed Type1"
Put all of the M code into the Advanced Editor:
And click "Close & Apply":
Then use this DAX to create a measure:
Count_Chart =
CALCULATE(
DISTINCTCOUNT('Table'[ID]),
'Table'[Index] = 1
)
And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Apologies, its been a few days. I was excited, as this seemed promising and it did actually achieve what you told me it would.
However, there is a problem I failed to mention - I need this unduplicated count to dynamically calculate with respect to a date filter. For example, consider the following data:
| CATEGORY | ITEM | ID | SELL_DATE |
| CAT1 | SHOES | 1 | 1/1/2025 |
| CAT1 | SHOES | 1 | 12/8/2024 |
| CAT1 | PANTS | 2 | 11/23/2024 |
| CAT2 | SHIRT | 3 | 2/1/2025 |
| CAT2 | DRESS_SHIRT | 4 | 11/2/2024 |
| CAT3 | SHOES | 1 | 12/27/2024 |
Consider the following desired outcomes based on date filter scenarios:
Filter 1: 1/1/2025 - 2/24/2025
- CAT1: 2 (PANTS and SHOES ordered on 1/1/2025)
- CAT2: 2 (SHIRT and DRESS_SHIRT)
- CAT3: 0
Filter 2: 10/1/2024 - 1/31/2025
- CAT1: 2 (the EARLIEST SHOES order and PANTS)
- CAT2: 1 (DRESS_SHIRT)
- CAT3: 0 (this order of shoes was not the EARLIEST and therefore is not counted)
Filter 3: 12/27/2024 - 1/31/2025
- CAT1: 1 (PANTS only bc the SHOES order in CAT1 is not the EARLIEST)
- CAT2: 0 (no items in this category is in the filtered range)
- CAT3: 1 (earliest instance of a SHOES order)
So, in summary, I need the solution to do the following:
- first filter the table by the date
- choose the earliest order of each category in the resulting table.