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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SagarJagga
Frequent Visitor

Need help with DAX

Hi All,

I need your help in framing a DAX.

Below is the sample data -

NameMetroSegmentSales
ANewMID55
AColumboMID60
BOtherMID100
CIndLarge200

 

I want to create a table by using Metro and Sum of Sales; Name will be in the filter.

Let me explain you the requirement with example. Let's say A Name has been selected from the filter. The corresponding segment is MID so in table, all the Metros corresponding to MID should be shown in the table i.e New, Columbo and Other. 

 

Regards,

Sagar

2 ACCEPTED SOLUTIONS
BeaBF
Super User
Super User

@SagarJagga Hi!

 

First, you need to have a distinct separate table for "Name", you can calculate the table with this formula:

NameTable = DISTINCT('Table'[Name])

Then, create a two measures:
SelectedSegment = VAR selitem = SELECTEDVALUE(NameTable[Name])
RETURN
CALCULATE(
    MAX('Table'[Segment]),
    'Table'[Name] = selitem,
    ALL()
)
FilteredSales =
VAR SegmentToFilter = [SelectedSegment]
RETURN
CALCULATE(
    SUM('Table'[Sales]),
    'Table'[Segment] = SegmentToFilter
)
 
and put in the matrix "Metro" and this last measure. You'll obtain:
BeaBF_0-1720514242879.png

If it's ok, please accept this answear as a solution.

 

BBF



View solution in original post

Anonymous
Not applicable

Hi @SagarJagga ,

 

Your solution is great, @BeaBF . Here I have another idea in mind, and I would like to share it for reference.

 

The steps are as follows:

 

  1. Create a new table:

vlinhuizhmsft_0-1720518788104.png

 

  1. Create a measure, the formula is as follows:

 

Measure =
VAR _my_se = VALUES('Table 2'[Table_Segment])
RETURN
CONCATENATEX(FILTER('Table','Table'[Segment] IN _my_se),1)​

 

  • Filtering operations on measure:

    vlinhuizhmsft_4-1720519103105.png
  • The result is shown in the figure with a slicer ,Table and Table2.
    vlinhuizhmsft_5-1720519147858.png

     

 

 

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Zhu
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Hi @SagarJagga ,

 

Your solution is great, @BeaBF . Here I have another idea in mind, and I would like to share it for reference.

 

The steps are as follows:

 

  1. Create a new table:

vlinhuizhmsft_0-1720518788104.png

 

  1. Create a measure, the formula is as follows:

 

Measure =
VAR _my_se = VALUES('Table 2'[Table_Segment])
RETURN
CONCATENATEX(FILTER('Table','Table'[Segment] IN _my_se),1)​

 

  • Filtering operations on measure:

    vlinhuizhmsft_4-1720519103105.png
  • The result is shown in the figure with a slicer ,Table and Table2.
    vlinhuizhmsft_5-1720519147858.png

     

 

 

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Zhu
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

 

BeaBF
Super User
Super User

@SagarJagga Hi!

 

First, you need to have a distinct separate table for "Name", you can calculate the table with this formula:

NameTable = DISTINCT('Table'[Name])

Then, create a two measures:
SelectedSegment = VAR selitem = SELECTEDVALUE(NameTable[Name])
RETURN
CALCULATE(
    MAX('Table'[Segment]),
    'Table'[Name] = selitem,
    ALL()
)
FilteredSales =
VAR SegmentToFilter = [SelectedSegment]
RETURN
CALCULATE(
    SUM('Table'[Sales]),
    'Table'[Segment] = SegmentToFilter
)
 
and put in the matrix "Metro" and this last measure. You'll obtain:
BeaBF_0-1720514242879.png

If it's ok, please accept this answear as a solution.

 

BBF



Hi @BeaBF ,

Why we are using different table for Name and using ALL() in segment calculation

@SagarJagga because we need to remove the native interaction between Name and pass only the filter on Segment, to obtain the three rows set to the same Segment of the Name selected. 

 

BBF

thanks for the explantion but why all is used. using seperate table to remove the interaction i understood

 

@SagarJagga for the same reason, because Name and Segment are in the same table, you need to "sfilter" the selection on Segment from the Name row context. 

In summary, ALL() is used to ensure that the MAX('Table'[Segment]) function considers all possible values in the Segment column of the Table, regardless of filters active in the context.

 

BBF

can you please attach your pbix file

 

Not sure why it is not working for me. i have tried by passing hard code value for Segment as well 

SagarJagga_0-1720516892988.png

 

@SagarJagga in the filter you have to use Name of Tablename, see my pbix

i can not open google drive due to limitations. can you please attached the file here

@SagarJagga i've sent it to your mail. Please let me know if it's ok and accept the solution.

 

BBF

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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