March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Below is a sample data - first 3 columns are my inputs. Total Supply, Match and Long are my calculated columns.
Total Supply = Current Quarter Supply + Previous quarter Long. Example Total Supply Q2 = 38 + 6 = 44
Match = Min(Outlook, Total Supply). Example Match Q2 = Min (41, 44) = 41
Long = Total Supply - Match. Example Long Q2 = 44-41 = 3
PowerBI gives a circular dependency error but Total Supply is actually using previous quarter Long and not current quarter long, so logically it is not circular.
Can anyone help replicate the measures in PowerBI?
Quarter | Supply | Outlook | Total Supply | Match | Long |
Q1 | 31 | 25 | 31 | 25 | 6 |
Q2 | 38 | 41 | 44 | 41 | 3 |
Q3 | 42 | 22 | 45 | 22 | 23 |
Q4 | 45 | 22 | 68 | 22 | 46 |
Hi,
Do you have a proper Date column? If yes, then share the download link of the PBI file.
Hi Ashish
Yeah I can add a quarter end date as below:
Quarter end date | Quarter | Supply | Outlook |
31-03-2023 | Q1 | 31 | 25 |
30-06-2023 | Q2 | 38 | 41 |
30-09-2023 | Q3 | 42 | 22 |
31-12-2023 | Q4 | 45 | 22 |
Hi,
That is definitely cicular logic. I misread your question initially.
Well, it may be circular but List.Accumulate can handle it.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIGEUamSrE60UpGIL4FkDAxBPONQUyQoJERmG8C4ptC+bEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Quarter = _t, Supply = _t, Outlook = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Quarter", Int64.Type}, {"Supply", Int64.Type}, {"Outlook", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Accumulate({1..[Quarter]},[Total=0, Match=0, Long=0],(state,current)=>[
Total = #"Changed Type"{current-1}[Supply] + state[Long],
Match = List.Min({Total,#"Changed Type"{current-1}[Outlook]}),
Long = Total-Match ]
)),
#"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"Total", "Match", "Long"}, {"Total", "Match", "Long"})
in
#"Expanded Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
Hi,
Thank you for sharing this.
@Ashish_Mathur I learned how to better carry multiple variables through the iterations, and how (and when) to address them in in each cycle ( like the " state[Long] " example). I am more and more impressed by the versatility of List.Accumulate.
Do you need this in Power BI? As a measure or calculated column? Or can it be done in Power Query?
Was trying to solve for it in a measure, but even if it is a PowerQuery it works..
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |