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

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.

Reply
Power_Mate
Helper I
Helper I

How to select the value based on rank

Hi All,

 

I am looking for the help on finding the right cost based on a another column.

Product_IdProduct_Cd

Product_Type

Cost
X00470156DED1459
Y00470156 324
Y00470156SED657
Y00470156LED23
Z0132789 78
C21127835DED567
C21127835 3217
Y00127835SED1789
F01127835LED368
S01697431LED3214
D106974321ZED1145
Y006974321 567
Z016974321LED1145
F016974321 987
MZ16974321FED1792
N19333247ZED1792
X00333247 1792
Y00333247SED1792
Z01333247 1478
C21333247 328
C21333247 679
Y00976179SED34789
F01976179LED14568
S01976179 35789
D10976179 3247
Y00976179CED3247
Z012749513 0
F012749513 0
MZ12749513ZED3256
N192749513LED0
M992749513SED7894
Q612749513 0

Above you can find the data related to the issue.

as part of the requirement I need to pick the cost value for each product_cd based on Product_type.

In product_type we have multiple values out of it we need to consider only 3.

On priority based we need pick ZED value of Product, If ZED value is not available then we need to pick SED value and if SED is not available then LED else 0. 

If we have all ZED,SED  and LED values we need to pick ZED.

 

For Example 1:

Product_IdProduct_CdProduct_TypeCost
X00470156DED1459
Y00470156 324
Y00470156SED657
Y00470156LED23

for Product_cd 470156 cost is 657.

Example 2 :

Product_IdProduct_CdProduct_TypeCost
Z012749513 0
F012749513 0
MZ12749513ZED3256
N192749513LED0
M992749513SED7894
Q612749513 0

 

for 'Product_cd' 2749513 Cost is 3256

All this should be happend dynamically by using DAX.

 

Thanks In advance.

 

Regards

Power Mate

1 ACCEPTED SOLUTION
mohammedadnant
Impactful Individual
Impactful Individual

Hi @Power_Mate 

 

Please try the following

mohammedadnant_0-1656414894530.png

 

FindCost = 

//[SumCost] = sum('Product Cost'[Cost]) <--- ANOTHER FORMULA

VAR _ZEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="ZED")

VAR _SEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="SED")

VAR _LEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="LED")

RETURN

IF ( ISBLANK(_ZEDCost),

IF(ISBLANK(_SEDCost), _ZEDCost,_SEDCost), _ZEDCost)

 

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

Thanks & Regards,
Mohammed Adnan
Learn Power BI: https://www.youtube.com/c/taik18

View solution in original post

3 REPLIES 3
Power_Mate
Helper I
Helper I

Do are we missing the third one i see only ZED and SED, or do we need to write one more IF for LED.

Can you please correct me if i am wrong

Power_Mate
Helper I
Helper I

Thanks for the help. Its matches for the requirement

mohammedadnant
Impactful Individual
Impactful Individual

Hi @Power_Mate 

 

Please try the following

mohammedadnant_0-1656414894530.png

 

FindCost = 

//[SumCost] = sum('Product Cost'[Cost]) <--- ANOTHER FORMULA

VAR _ZEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="ZED")

VAR _SEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="SED")

VAR _LEDCost = CALCULATE( [SumCost], ALL('Product Cost'[Product_Type]), 'Product Cost'[Product_Type]="LED")

RETURN

IF ( ISBLANK(_ZEDCost),

IF(ISBLANK(_SEDCost), _ZEDCost,_SEDCost), _ZEDCost)

 

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

Thanks & Regards,
Mohammed Adnan
Learn Power BI: https://www.youtube.com/c/taik18

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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