The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi there,
I have a basic table setup:
tblProducts (ProductID)
tblStores (StoreID)
tblData (StoreID, ProductID, Date, SOH, Sales)
tblCalendar (Date)
I am trying to count the line (ProductID & StoreID). That have More than zero SOH for the latest date of data and zero sales over 50 days.
Solved! Go to Solution.
I was finally able to get this calculation working, by using CROSSJOIN. Other methods were just too slow.
Here is the measure, hope it is able to help someone else.
Phantom Stock =
CALCULATE (
SUMX (
CROSSJOIN (
VALUES ( tblProducts[ArticleCode] ),
VALUES ( tblStores[StoreCode] )
),
IF (
[Stock on Hand Latest Date] > 0
&& [Volume Sales Total (X Days)] <= 0,
[Stock on Hand Latest Date],
BLANK ()
)
)
)
Here are the 2 supporting measures.
Stock on Hand Latest Date =
VAR _MaxDate = CALCULATE(MAX(tblCalendar[Date]),ALL(tblCalendar))
RETURN
CALCULATE (
[Stock on Hand Total],
FILTER (
tblCalendar,
tblCalendar[Date] = _MaxDate
)
)
The Variable called _Days, is just a list of days in weeks, (1 Week = 7, 2 Weeks = 14 etc...)
Volume Sales Total (X Days) =
VAR _CurrentDate = CALCULATE(MAX(tblCalendar[Date]),ALL(tblCalendar))
VAR _Days = max(sptWeeks[Days])
VAR _StartDate = _CurrentDate - _Days
RETURN
CALCULATE(
[Volume Sales Total],
FILTER(
tblCalendar,
tblCalendar[Date] > _StartDate && tblCalendar[Date] <= _CurrentDate
)
)
I was finally able to get this calculation working, by using CROSSJOIN. Other methods were just too slow.
Here is the measure, hope it is able to help someone else.
Phantom Stock =
CALCULATE (
SUMX (
CROSSJOIN (
VALUES ( tblProducts[ArticleCode] ),
VALUES ( tblStores[StoreCode] )
),
IF (
[Stock on Hand Latest Date] > 0
&& [Volume Sales Total (X Days)] <= 0,
[Stock on Hand Latest Date],
BLANK ()
)
)
)
Here are the 2 supporting measures.
Stock on Hand Latest Date =
VAR _MaxDate = CALCULATE(MAX(tblCalendar[Date]),ALL(tblCalendar))
RETURN
CALCULATE (
[Stock on Hand Total],
FILTER (
tblCalendar,
tblCalendar[Date] = _MaxDate
)
)
The Variable called _Days, is just a list of days in weeks, (1 Week = 7, 2 Weeks = 14 etc...)
Volume Sales Total (X Days) =
VAR _CurrentDate = CALCULATE(MAX(tblCalendar[Date]),ALL(tblCalendar))
VAR _Days = max(sptWeeks[Days])
VAR _StartDate = _CurrentDate - _Days
RETURN
CALCULATE(
[Volume Sales Total],
FILTER(
tblCalendar,
tblCalendar[Date] > _StartDate && tblCalendar[Date] <= _CurrentDate
)
)
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
80 | |
71 | |
51 | |
50 |
User | Count |
---|---|
128 | |
122 | |
77 | |
64 | |
60 |