Forum Discussion
Calculated Measure Using Multiple Dates and Multiple Percentages
- 6 years ago
I'm not sure I fully understand your goal, but you are going to have to normalize this table for this to work at all in DAX. The below M code in Power Query will transform your original table to the following:
Does that help? Now you just need to filter on the dates and run some cumulative totals. If this is going down the right track, post back if you need additional help with the DAX side, or if the above doesn't look right.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJQ0lEyUwUSRmh8YwTfwgIkYGEAIg0NDHQMDAz0DAyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"1st Invoice Date" = _t, #"1st Invoice % Due" = _t, #"2nd Invoice Date" = _t, #"2nd Invoice % Due" = _t, #"3rd Invoice Date" = _t, #"3rd Invoice % Due" = _t, #"Overall Weight %" = _t, #"Total Net Fee" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"1st Invoice Date", type date}, {"1st Invoice % Due", Percentage.Type}, {"2nd Invoice Date", type date}, {"2nd Invoice % Due", Percentage.Type}, {"3rd Invoice Date", type date}, {"3rd Invoice % Due", Percentage.Type}, {"Overall Weight %", Percentage.Type}, {"Total Net Fee", Int64.Type}}), #"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"), #"Changed Type1" = Table.TransformColumnTypes(#"Demoted Headers",{{"Column1", type any}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}, {"Column5", type any}, {"Column6", type any}, {"Column7", type any}, {"Column8", type any}}), #"Transposed Table" = Table.Transpose(#"Changed Type1"), #"Added Custom" = Table.AddColumn(#"Transposed Table", "Date", each if Value.Is([Column2], type date) = true then [Column2] else null, type date), #"Filled Down" = Table.FillDown(#"Added Custom",{"Date"}), #"Extracted Text After Delimiter" = Table.TransformColumns(#"Filled Down", {{"Column1", each Text.AfterDelimiter(_, " "), type text}}), #"Filtered Rows" = Table.SelectRows(#"Extracted Text After Delimiter", each ([Column1] = "Invoice % Due" or [Column1] = "Net Fee")), #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Column1]), "Column1", "Column2"), #"Changed Type2" = Table.TransformColumnTypes(#"Pivoted Column",{{"Invoice % Due", Percentage.Type}, {"Net Fee", Currency.Type}}) in #"Changed Type2"1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
I find Power Query useful for certain things, but my data model is coming from an Alteryx abstraction from dozens of excel workbooks, so I may try the unpivot there first, but I've often found transposing and unpivoting data to be a little simpler and easier in Power Query, so I'll let you know what happens.
Thanks again for the quick response!
Understood. Yeah, doing transformations at the source can help as well if that is possible. My point was, just don't try to do data modeling in the DAX model itself. 😁