Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
samioberoi
Helper III
Helper III

Specific value to be added from a value derived from a conditional value

Hi,

I need some help please. I have got three tables as below. In Table A, I created a calculated column called as BAND COL below and the relationship between the tables is as created below between Table A and Table B on INDEX column and between Table A and Table C it is inactive relationship created on BAND COL and DOM. I want to create a measure, which should calculate with the logic as if it is BBC from code column and if it is TL, SS and SE from Prod column and if it is ENG and UNK from Country column then it should just normally add up those values from BALANCE column, but if it is BBC from code column and it is PT from PROD column and it is ENG from Country column then it should take that aggregated value and add it with the other particular value from Table B where it is MPA from DOM column and it is ICRP2 from PTCOL . The reason I created the Dimension table Table C is so that it will filter the results similarly from all other tables linked to it.

 

TABLE A

CODE

PROD

COUNTRY

BALANCE

BAND COL

INDEX

BBC

TL

ENG

807

ML (P1)

1

BBC

SS

ENG

162

ML (P1)

2

BBC

TL

UNK

56

ML (P1)

3

BBC

SS

UNK

13

ML (P1)

4

BBC

SE

ENG

1

ML (P1)

5

BBC

FL

ENG

109

FL (P1)

6

CRI2

FL

ENG

578

 

7

BBC

PT

ENG

836

PTML (P1)

8

CRI2

PT

ENG

107

 

9

CRI1

PT

ENG

157

 

10

 

TABLE B

DOM

PTCOL

SUB_AMOUNT

INDEX

BBC

MSL

0

1

MPA

MSL

0

2

MPA

ICRP1

0

3

MPA

ICRP2

-573

4

EUE

FL-PRE 2012

0

5

ENG

FL

0

6

 

TABLE C

DISTINCT_CODE

INDEX

ML (P1)

1

FL (P1)

2

PTML (P1)

3

 

 

samioberoi_1-1739922910326.png

 

 

 

Results Table

DISTINCT CODE FROM TABLE C

RESULTS COL

ML (P1)

1039

FL (P1)

109

PTML (P1)

836

 

 

Thanks for any sort of help.

 

8 REPLIES 8
v-xinc-msft
Community Support
Community Support

Hi @samioberoi ,

Did the replies above offered help you solve the problem, if it helps, you can consider to accept it as a solution so that more user can refer to, or if you have other problems, you can offer some information so that can provide more suggestion for you.

Best regards,

Lucy Chen

samioberoi
Helper III
Helper III

Hi ryan_mayu,

 

Thanks for your reply and apologies for the mistake from my side in the Results Table. It should be like if it is specifically FL (P1) then it should take 109 from Table A and add/subtract that with -573 from Table B and should give me its value equal to something like 109 + (-573) = -464 and filtering should me done in the visual by the DISTINCT_CODE column from Table C. Rest of the codes like ML (P1) and PTML (P1) should be calculated normally. 

 

Actual Amended Results Table

DISTINCT CODE FROM TABLE C

RESULTS COL

ML (P1)

1039

FL (P1)

-464

PTML (P1)

836


Hope i could make it proper and clear this time and sorry for not explaining it properly in the first post.
Thanks.

@samioberoi 

 

since I can't find and relationship between FL(P1) row in Table A and the -573 in the table B, how did you get the band col? could you pls share the DAX? 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,
This is the DAX i used for Band Col below:

BAND_COL = if (Table A[PROD] in {"TL","SS", "SE"}
                      && Table A[CODE] = "BBC"
                      && Table A[COUNTRY] in {"ENG", "UNK"},
                       "ML (P1),

                      if (Table A[PROD] = "FL"
                      && Table A[CODE] = "BBC"
                      && Table A[COUNTRY] = "ENG",
                       "FL (P1),

                      if (Table A[PROD] = "PT"
                      && Table A[CODE] = "BBC"
                      && Table A[COUNTRY] = "ENG"
                       "PTML (P1)"

 

 

And this measure below is what i tried to create for the required calculation i am trying to get the right results for. It seems to be giving the right value for FL (P1) where the sum needs to be done from a figure from Table A with a value from Table B, but i can't get the other values as normal for "ML (P1)", "PTML (P1)”.

 

Measure =

VAR LT =

SWITCH(

        TRUE(

                      SELECTEDVALUE(Table A[PROD] in {"TL","SS", "SE"}
                      && SELECTEDVALUE(Table A[CODE] = "BBC"
                      && SELECTEDVALUE(Table A[COUNTRY] in {"ENG", "UNK"},
                       "ML (P1)",

                     SELECTEDVALUE(Table A[PROD] = "FL"
                      && SELECTEDVALUE(Table A[CODE] = "BBC"
                      && SELECTEDVALUE(Table A[COUNTRY] = "ENG",
                       "FL (P1)”,

                      SELECTEDVALUE(Table A[PROD] = "PT"
                      && SELECTEDVALUE(Table A[CODE] = "BBC"
                      && SELECTEDVALUE(Table A[COUNTRY] = "ENG"
                       "PTML (P1)”

VAR X90 = CALCULATE(
                     SUM(TABLE A [BALANCE]),

                    TREATAS(VALUES(TABLE C [DISTINCT COUNT], TABLE A [BUCKET COL])
                    )

VAR TBVALUE = CALCULATE(

           LOOKUPVALUE(

                              TABLE B [SUB_AMOUNT],

                               TABLE B [DOM] = “MPA”

                              TABLE B [PTCOL] = “ICRP2”

                             ))
RETURN

IF(

    LT = "FL (P1)”,

   X90 + IF (ISBLANK (TBVALUE, 0, TBVALUE),

LT

 

 

Hope i could explain better and for any info please let me know. 

Appreciate a lot for your effort to help. 

still can't find any relationship between TABLE A and B.could you pls explain why FLP1 will minus -573? I can't find any related columns in both tables.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi ryan_mayu,

 

I created index column in both Table A and Table B to be able to make one to one relationship happen between the two. Beween the Table A and Table C (which i created to be able to dynamically filter based on DISTINCT_CODE column between the other tables as well) there is an inactive relationship for DISTINCT_CODE column from Table C and BAND_COL from Table A.  Something like as i am trying to show in the image below. I may be doing something wrong. 
It can be FLP1 will plus -573 (From Table B). The last DAX above called Measure is calculating FLP1 + (-573) properly, the only thing it is not doing is that it doesn't give me the aggregated values calculated for "ML (P1)", "PTML (P1)”.

Me being not so knowledgeable about PBI i definitely am doing something wrong somewhere.

 

samioberoi_1-1740056776775.png

 

 

Much appreciated!

@samioberoi 

the index are not matching for FLP1 and -573. One is index 4 and the other is 6. Still don't know the logic of calculation. If FLP1 will always add the subtotal in table B, you can try 

=if (selectedvalue(DISTINCT_CODE) ="FL(P1)", XXXX) 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@samioberoi 

you can try this

Measure = SUMX(FILTER('Table A','Table A'[BAND COL]=MAX('Table C'[DISTINCT_CODE])),'Table A'[BALANCE])
 
11.PNG
 
pls see the attachment below




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors