Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi all,
I would like to have a recursion metric (not a calculated column) to use in a chart.
Alow me to explain the problem (you can find attached a PBI desktop file with dummy data for this problem) :
In my data model I have 3 tables:
Here is how data model is built:
So, I would like to build 3 principal metrics:
What I have managed to do properly, in the attached powerbi desktop file, was to build the New cases metric. Total and refill metrics are wrongly calculated and I would like you to help me out on this task, which I understand it might not be simple.
What I would like to build:
Let me know if you need any more information.
Thank you
Solved! Go to Solution.
Hi all!
I solved my own problem! 🙂
Here's how I did it, in case someone else is coming to this problem in future:
The solution found was not with DAX, but with good old SQL.
What I did was to generate in SQL a query that returns a table specifically for the Refill cases calculations. This table resulted from a simple CROSS JOIN, something along this lines:
SELECT DISTINCT
a.ProductID
,DATEADD(WW, DATEDIFF(WW, 7, '01-01-' + LEFT( dateID,4 ) ) + ( CAST( RIGHT( dateID, 2 ) AS int)-1), 7) WeekStart
,b.[geoID]
,b.[Type]
,b.value as Refills
FROM facTable a
CROSS JOIN (
SELECT
ProductID
,dateID as dateCode
,[geoID]
,[Type]
,SUM( [value] ) as value
FROM facTable
WHERE
DimProductID = 'xpto'
AND Type in ('a','b','d')
AND dateID< ( SELECT MAX( dateID) FROM facTable WHERE ProductID = 'xpto')
GROUP BY [ProductID], [dateID ], [geoID],[Type]
) as b
WHERE a.ProductID = 'xpto' AND DateCode< a.dateID
Then I loaded this table into PBI and connected to the respectivedimensional tables, and thats it 🙂
Hope this helps someone in future.
Thanks. 🙂
Hi all!
I was thinking that, perhaps, a calculated table would help with the refill calculations, specifically for when I want to report that metric with the geoID's.
Would this be a viable solution?
What would be the performance impacts of this, when data grows along the time (this is weekly data, by the way)?
Thanks in advance.
Hi all!
I solved my own problem! 🙂
Here's how I did it, in case someone else is coming to this problem in future:
The solution found was not with DAX, but with good old SQL.
What I did was to generate in SQL a query that returns a table specifically for the Refill cases calculations. This table resulted from a simple CROSS JOIN, something along this lines:
SELECT DISTINCT
a.ProductID
,DATEADD(WW, DATEDIFF(WW, 7, '01-01-' + LEFT( dateID,4 ) ) + ( CAST( RIGHT( dateID, 2 ) AS int)-1), 7) WeekStart
,b.[geoID]
,b.[Type]
,b.value as Refills
FROM facTable a
CROSS JOIN (
SELECT
ProductID
,dateID as dateCode
,[geoID]
,[Type]
,SUM( [value] ) as value
FROM facTable
WHERE
DimProductID = 'xpto'
AND Type in ('a','b','d')
AND dateID< ( SELECT MAX( dateID) FROM facTable WHERE ProductID = 'xpto')
GROUP BY [ProductID], [dateID ], [geoID],[Type]
) as b
WHERE a.ProductID = 'xpto' AND DateCode< a.dateID
Then I loaded this table into PBI and connected to the respectivedimensional tables, and thats it 🙂
Hope this helps someone in future.
Thanks. 🙂
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
73 | |
72 | |
39 | |
31 | |
26 |
User | Count |
---|---|
97 | |
87 | |
43 | |
40 | |
35 |