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
Dear All,
I need your help for my below need. Here the explanations :
To make it simpler, let's say I have 1 fact table called "PROJECTION" in which I project the stock of my components. In the attached picture I only have 2 components A & B.
Every month I take "a picture" of this data in my ERP and thanks to Query I combine all pictures in the PROJECTION table.
The column "PICTURE DATE" is the month I have extracted the data (here only OCT24 & NOV24). In each picture, we project for each item a quantity available and a quantity blocked AND for each end of coming months (that are in column "PROJECTION DATE").
I already created a DAX measure called "TOTAL QTY" as per :
Solved! Go to Solution.
hi @yoa380 ,
try like:
V_TOTAL QTY_NEW =
VAR selectedpicture = SELECTEDVALUE(SELECT_PIC[ShortDate])
RETURN
IF(
YEAR(PROJECTION DATE) <= YEAR(TODAY()),
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY]*PROJECTION[COST_WAC]
),
PROJECTION[PICTURE DATE]=selectedpicture
),
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY]*RELATED(BUD[COST_BUD]
),
PROJECTION[PICTURE DATE]=selectedpicture
)
)
Hi @yoa380 ,
Can you please use this and check does it works in the scenario you mentioned.
DAX:
V_TOTAL QTY_NEW =
VAR selectedpicture = SELECTEDVALUE(SELECT_PIC[ShortDate])
RETURN
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY] *
IF(
YEAR(PROJECTION[PROJECTION DATE]) <= YEAR(TODAY()),
RELATED(WAC[COST]), -- Use WAC cost if projection date is in the current year or earlier
RELATED(BUD[COST]) -- Use BUD cost if projection date is in the future
)
),
PROJECTION[PICTURE DATE] = selectedpicture
)
This measure (V_TOTAL QTY_NEW) will dynamically adjust based on the year of PROJECTION DATE and multiply TOTAL QTY by either WAC or BUD cost as specified.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara.
Data Analyst | MSBI Developer | Power BI Consultant
Hi @yoa380 ,
Can you please use this and check does it works in the scenario you mentioned.
DAX:
V_TOTAL QTY_NEW =
VAR selectedpicture = SELECTEDVALUE(SELECT_PIC[ShortDate])
RETURN
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY] *
IF(
YEAR(PROJECTION[PROJECTION DATE]) <= YEAR(TODAY()),
RELATED(WAC[COST]), -- Use WAC cost if projection date is in the current year or earlier
RELATED(BUD[COST]) -- Use BUD cost if projection date is in the future
)
),
PROJECTION[PICTURE DATE] = selectedpicture
)
This measure (V_TOTAL QTY_NEW) will dynamically adjust based on the year of PROJECTION DATE and multiply TOTAL QTY by either WAC or BUD cost as specified.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara.
Data Analyst | MSBI Developer | Power BI Consultant
I think I found the solution, hope it will be stable ....
I use filters of calculate and do +
V_TOTAL QTY_NEW =
VAR selectedpicture = SELECTEDVALUE(SELECT_PIC[ShortDate])
RETURN
CALCULATE(
SUMX(PROJECTION, PROJECTION[TOTAL QTY]*PROJECTION[COST_WAC]), PROJECTION[PICTURE DATE]=selectedpicture, YEAR(PROJECTION DATE)<=YEAR(TODAY())) +
SUMX(PROJECTION, PROJECTION[TOTAL QTY]*PROJECTION[COST_BUD]), PROJECTION[PICTURE DATE]=selectedpicture, YEAR(PROJECTION DATE)>YEAR(TODAY()))
Hello, thanks for quick reply. I cannot do that, first when I type IF( YEAR( ... it doesn't offer the choice to put PROJECTION DATE. It only shows measures from the table, not the other simple columns.
And if I force the formula with it, it will tell me : impossible to determine a unique value for the "projection date" column in the table. This can happen when a measurement formula refers to a column that contains many values, without specifying an aggregation such as min, max, count or sum to get a unique result.
hi @yoa380 ,
try like:
V_TOTAL QTY_NEW =
VAR selectedpicture = SELECTEDVALUE(SELECT_PIC[ShortDate])
RETURN
IF(
YEAR(PROJECTION DATE) <= YEAR(TODAY()),
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY]*PROJECTION[COST_WAC]
),
PROJECTION[PICTURE DATE]=selectedpicture
),
CALCULATE(
SUMX(
PROJECTION,
PROJECTION[TOTAL QTY]*RELATED(BUD[COST_BUD]
),
PROJECTION[PICTURE DATE]=selectedpicture
)
)
Yes, it seems to work thanks ! same result as my previous addition but shorter DAX
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
User | Count |
---|---|
26 | |
21 | |
20 | |
13 | |
12 |
User | Count |
---|---|
40 | |
27 | |
27 | |
21 | |
19 |