Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello,
I have table as below:
ID | Amount | Subtract from ID |
1 | -100 | 3 |
2 | 200 | |
3 | 300 | |
4 | -50 | 2 |
5 | -10 | 3 |
Can I get to the goals table below in power bi?
Goals:
ID | Amount | Subtract from ID | Final |
1 | -100 | 3 | 0 |
2 | 200 | 150 | |
3 | 300 | 50 | |
4 | -50 | 2 | 0 |
5 | -150 | 3 | 0 |
Solved! Go to Solution.
Hi, @alya1
Based on your description, I created a measure using the following DAX:
Result =
VAR _ID =
SELECTEDVALUE ( 'Table'[ID ] )
VAR _table =
SUMMARIZE (
ALL ( 'Table' ),
'Table'[ID ],
'Table'[Subtract from ID ],
'Table'[Amount ]
)
VAR _amount =
SELECTEDVALUE ( 'Table'[Amount ] )
VAR _blank =
FILTER ( _table, 'Table'[Subtract from ID ] = _ID )
RETURN
IF (
_ID IN SELECTCOLUMNS ( _blank, 'Table'[Subtract from ID ] ),
_amount + SUMX ( _blank, 'Table'[Amount ] ),
0
)
Put the corresponding column and this measure in the table visual, and the result is as follows:
I've provided the PBIX file used this time below.
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @alya1
Based on your description, I created a measure using the following DAX:
Result =
VAR _ID =
SELECTEDVALUE ( 'Table'[ID ] )
VAR _table =
SUMMARIZE (
ALL ( 'Table' ),
'Table'[ID ],
'Table'[Subtract from ID ],
'Table'[Amount ]
)
VAR _amount =
SELECTEDVALUE ( 'Table'[Amount ] )
VAR _blank =
FILTER ( _table, 'Table'[Subtract from ID ] = _ID )
RETURN
IF (
_ID IN SELECTCOLUMNS ( _blank, 'Table'[Subtract from ID ] ),
_amount + SUMX ( _blank, 'Table'[Amount ] ),
0
)
Put the corresponding column and this measure in the table visual, and the result is as follows:
I've provided the PBIX file used this time below.
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Jianpeng, thank you so much for the clean and effective DAX!
May I ask you to please explain the steps please? specifically VAR _table and the RETURN line please.
Hi, @alya1
Thank you very much for your reply. First_ID returns the ID of the current table visual row, _amount something similar:
_table generates a table of variables that looks like this:
_blank returns a table of variables that contains only the current _ID. Finally, use the SELECTCOLUMNS method to select the ID column of the _blank table, and then determine whether the _ID of the current row is in this column. If the current ID is in this table, then the amount corresponding to the current ID + the amount that matches it. That's what you're looking for.
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you Jianpeng!!
User | Count |
---|---|
16 | |
15 | |
14 | |
12 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |