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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Hemanth96
Frequent Visitor

Return Text column based on other column condition

Hi, I'm a noobie to DAX and need help. I have a table with product names and store wise sales.

 

I want to see a visual matrix table where the prodnames should be displayed if either store 1 or store 2 has sales. If there's no sale in either of the store for that prodname, it shouldn't appear in the table. Please help me how to do this.

 

prodnamestore1store2store 3store 4
prd110080 26
prd2 607212
prd350   
prd4  6629
prd5 81023
prd6   2868
prd7 118 11 

 

OUTPUT

 

prd#store1store2store 3store 4
prd110080 26
prd2 607212
prd350   
prd5 81023
prd7 118 11 
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Hemanth96 ,

 

Here I suggest you to create measures by dax and add measures into visual level filter to filter your visual.

Measure is based on your table.

Table1:

RicoZhou_1-1663573392461.png

Measure 1 = 
IF(ISBLANK(SUM('Table'[store1]))&& ISBLANK(SUM('Table'[store2])),0,1)

Table2:

RicoZhou_0-1663573379947.png

Measure 2 = 
VAR _STORE1 = CALCULATE(SUM('Table (2)'[Value]),FILTER('Table (2)','Table (2)'[Attribute] = "store 1"))
VAR _STORE2 = CALCULATE(SUM('Table (2)'[Value]),FILTER('Table (2)','Table (2)'[Attribute] = "store 2"))
RETURN
IF(ISBLANK(_STORE1)&&ISBLANK(_STORE2),0,1)

Create visual by columns , add measure into visual level filter and set it to show items when value =1.

Result is as below.

RicoZhou_2-1663573486345.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Hemanth96 ,

 

Here I suggest you to create measures by dax and add measures into visual level filter to filter your visual.

Measure is based on your table.

Table1:

RicoZhou_1-1663573392461.png

Measure 1 = 
IF(ISBLANK(SUM('Table'[store1]))&& ISBLANK(SUM('Table'[store2])),0,1)

Table2:

RicoZhou_0-1663573379947.png

Measure 2 = 
VAR _STORE1 = CALCULATE(SUM('Table (2)'[Value]),FILTER('Table (2)','Table (2)'[Attribute] = "store 1"))
VAR _STORE2 = CALCULATE(SUM('Table (2)'[Value]),FILTER('Table (2)','Table (2)'[Attribute] = "store 2"))
RETURN
IF(ISBLANK(_STORE1)&&ISBLANK(_STORE2),0,1)

Create visual by columns , add measure into visual level filter and set it to show items when value =1.

Result is as below.

RicoZhou_2-1663573486345.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

You didn't specify if you need this in Power Query or Power BI.  Here is a Power Query option.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY2xDcAgDARXiVxTYBOMMwuiywBR9i/CB1ui+Jf8p5N7p+e9mRJxzrMNdcyI0kg/FF8UqAGxBCvzrKGsODm3URXWFaj6bHgLWUogPTZNDK4Fa9iYzSnzejc+", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [prodname = _t, store1 = _t, store2 = _t, #"store 3" = _t, #"store 4" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"prodname", type text}, {"store1", Int64.Type}, {"store2", Int64.Type}, {"store 3", Int64.Type}, {"store 4", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each [store1] ?? 0 +[store2] ?? 0 ),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Custom] <> 0))
in
    #"Filtered Rows"

 

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

 

Note:  Data like this should be unpivoted before being loaded into Power BI.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.