Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi all!
I have a table that shows me the current state per order:
Order Number | Article | State 1 | State 2 | Quantity |
5556 | Bike 1 | 60 | 1 | 500 |
5557 | Bike 2 | 50 | 3 | 600 |
Then I have a second table that shows me for each article the necessary steps:
Article | State 1 | Description |
Bike 1 | 20 | Assembly |
Bike 1 | 50 | Drill |
Bike 1 | 60 | Mount |
Bike 1 | 20 | Assembly |
Bike 1 | 30 | Drill |
Now I would like to calculate the next step (calculated column) in the first table based on this conditions:
How would you do that in DAX?
Solved! Go to Solution.
Hi @joshua1990 ,
You can create a calculated column as below in table 1 to achieve the first condition:
Description =
CALCULATE (
MAX ( 'Table 2'[Description] ),
FILTER (
'Table 2',
'Table 2'[Article] = 'Table 1'[Article]
&& 'Table 1'[State 2] IN { 1, 2 }
)
)
And for the second condition, I'm not clear about " table 2 for the next state 1". What's the meaning of that? Could you please explain more on it base on the current data of table 1 and table 2? Thank you.
Best Regards
Hi @joshua1990,
Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.
Best Regards
Hi,
@v-yiruan-msft 's solution should help you to solve your issue. Another interesting approach to this is to use OFFSET function described here: How OFFSET in DAX will make your life easier – Data – Marc (data-marc.com)
I am not sure if that would be the optimal solution in the end. So here is another option to consider:
Is there a particular need to use a calculated column? You could for example create this kind of measure:
var _state1 = MAX(Table1[state1])
var _state2 = MAX(Table1[state2])
return
IF(_state2=3,"Finished",
CALCULATE(MAX(Table2[description]),ALL(Table2[state1]),Table2[state1]=_state1)
)
If you need an additional logic for state2 = 2 then use SWITCH + TRUE:
var _state1 = MAX(table1[state1])
var _state2 = MAX(table1[state2])
var _nextstate1 = CALCULATE(MIN(Table2[state1]),ALL(Table2[state1]),Table2[state1]>_state1)
return
SWITCH(TRUE(),
_state2 = 1, CALCULATE(MAX(Table2[description]),ALL(Table2[state1]),Table2[state1]=_state1),
_state2 = 2,CALCULATE(MAX(Table2[description]),ALL(Table2[state1]),Table2[state1]=_nextstate1),
_state2 = 3, "Finished")
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
Proud to be a Super User!
Hi @joshua1990 ,
You can create a calculated column as below in table 1 to achieve the first condition:
Description =
CALCULATE (
MAX ( 'Table 2'[Description] ),
FILTER (
'Table 2',
'Table 2'[Article] = 'Table 1'[Article]
&& 'Table 1'[State 2] IN { 1, 2 }
)
)
And for the second condition, I'm not clear about " table 2 for the next state 1". What's the meaning of that? Could you please explain more on it base on the current data of table 1 and table 2? Thank you.
Best Regards
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
49 | |
26 | |
21 | |
15 | |
12 |
User | Count |
---|---|
57 | |
49 | |
44 | |
19 | |
18 |