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

Be 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

Reply
Alyona_BI
Helper II
Helper II

Retrieve the value from text field based on condition and put it in each row in the table

Hi all! 
I have the task and I can't find the solution by myself and didn't find any solution at forum, so I am really hope for your help. 

 

I have the following table: 

PlantProductValue
AAAWater10
AAAJuice15
AAAChips25
BBBWater50
BBBJuice10
BBBChips10
CCCWater5
CCCJuice55

 

I need to identify the plant which have the biggest sum of Value and to put the name of the plant in each row. So the result should be (plant BBB has the maximum sum of value = 70, while AAA has 50 and BBB has 60): 

PlantProductValuePlant with maximum sum of value
AAAWater10BBB
AAAJuice15BBB
AAAChips25BBB
BBBWater50BBB
BBBJuice10BBB
BBBChips10BBB
CCCWater5BBB
CCCJuice55BBB

Additional comments: in reality the table is much bigger with a lot of extra columns. The plant with biggest value should be identified dynamically based on selections in slicers. 

 

Could anybody help me to calculate this? 

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

It is because you have not created the separate product-table, I have updated the pbix-file you shared here pbix

View solution in original post

6 REPLIES 6
sturlaws
Resident Rockstar
Resident Rockstar

could you share a screenshot of your data model, specifically the relationship between the product dimension and the fact table?

 

@sturlaws both of them are in the same table. I created the example in PBI, added both formulas (mine and yours) and put it in the google drive: 

https://drive.google.com/file/d/1amtgjt9v7v7Fu5DcGxIgsCvFQGp0OkJf/view?usp=sharing

 

In this example at the tab "Task" I added description of my complete real task, so maybe the context will bring more understanding.. 

 

Alyona_BI
Helper II
Helper II

@sturlaws hi! Thanks for your help. 

I have my own a little bit similar calculation: 

VAR _Table = CALCULATETABLE(
GROUPBY(Table,
Table[Plant],
"ND", SUMX(CURRENTGROUP (), Table[Value]))
)
VAR _Max = MAXX(_Table, [ND])
RETURN MAXX(FILTER(_Table, [ND] = _Max), [Plant])
 
It doesn't work. Unfortunately your variant too. The result is: 

Alyona_BI_0-1653652420523.png

So the result in each row should be "Packer-Deparker", which we see in the Total row, but not in all rows (( 

 

Maybe you have an idea why this is so?

It is because you have not created the separate product-table, I have updated the pbix-file you shared here pbix

It works. Many thanks! 

sturlaws
Resident Rockstar
Resident Rockstar

Hi, @Alyona_BI,

 

try to create this measure:

MaxPlant =
VAR _product =
    VALUES ( DimProduct[Product] )
VAR _allPlants =
    CALCULATETABLE (
        ADDCOLUMNS (
            VALUES ( 'Table'[Plant] ),
            "sumValue", CALCULATE ( SUM ( 'Table'[Value] ) )
        ),
        FILTER ( ALL ( 'Table' ), 'Table'[Product] IN _product )
    )
VAR _maxValue =
    MAXX ( _allPlants, [sumValue] )
VAR _maxPlant =
    MAXX ( FILTER ( _allPlants, [sumValue] = _maxValue ), 'Table'[Plant] )
RETURN
    _maxPlant

 

For this measure to work, you have to create a product-table, dimProduct, with all the distinct values for products. dimProduct should not have a relationship to the main-table, or have the relationship set to inactive.

Add DimProduct[Product] to a slicer in your report, and add the MaxPlant-measure to the table-visual:

sturlaws_0-1653651227080.png

If you want the slicer to filter the table, you can create this measure

filterProduct = var _tableProduct = VALUES('Table'[Product])
return
COUNTROWS(FILTER(VALUES(DimProduct[Product]),_tableProduct in VALUES(DimProduct[Product])))

 

and add it to the filter pane of the table-visual: 

sturlaws_2-1653651379094.png

 

 

I am behind a very strict firewall today, so I have no way of sharing the sample report with you, sorry about that.

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

 

 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.