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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
lpriceFTW
Helper II
Helper II

If a group of rows contains at least one of the filtered values, return the entire group of rows

I want to use DAX to select a group of rows containing a common value in field X, so long as there exists at least one instance/row of a filter value in field Y.

 

For example, take the following table:

 

Invoice No.StateAmt
10001TX100

10001

WV50
10001PA50
10002WA50
10002VA100
10003IL50
10004TX100

 

And the following filter:

lpriceFTW_0-1671576015819.png

 

 

Based on the filtered value ("TX"), the DAX/method will return all rows of each invoice containing at least one row with TX in the state field. Therefore, when the filter is applied, the returned data will be:

 

Invoice No.StateAmt
10001TX100

10001

WV50
10001PA50
10004TX100

 

Basically, since at least one rows of invoices 10001 and 10004 contained a value of "TX" in the state field, I want to return all the rows from those invoice.

 

I am trying to make it so this calculation changes based on the filtered value. So if the report user filtered to PA, TX, and WV, then the calculation would pull all the rows of invoice data of any invoice containing at least one row of any of the states that were filtered for.

 

This can involve calculated columns, measures, filter settings, etc.

 

Thanks

 

 

1 ACCEPTED SOLUTION
bolfri
Super User
Super User

Step 1: Create a new table with states:

dim_state = GROUPBY('Sample';'Sample'[State])
 
Step 2: Create a measure Amount:
Amount =
var state_list = VALUES(dim_state[State])
var invoice_list = SUMMARIZE(FILTER(ALL('Sample');'Sample'[State] in state_list);'Sample'[Invoice No.])
return SUMX(
        FILTER('Sample';OR('Sample'[State] in state_list;'Sample'[Invoice No.] in invoice_list));
        'Sample'[Amt]
        )
 
state_list contains information about selected states
invoice_list contains information about all invoice number that matches the states
measure return number of amount column when the state is in state list or invoice number in invoice list
 
bolfri_0-1671583288878.png

I hope this works for you 🙂





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
bolfri
Super User
Super User

Step 1: Create a new table with states:

dim_state = GROUPBY('Sample';'Sample'[State])
 
Step 2: Create a measure Amount:
Amount =
var state_list = VALUES(dim_state[State])
var invoice_list = SUMMARIZE(FILTER(ALL('Sample');'Sample'[State] in state_list);'Sample'[Invoice No.])
return SUMX(
        FILTER('Sample';OR('Sample'[State] in state_list;'Sample'[Invoice No.] in invoice_list));
        'Sample'[Amt]
        )
 
state_list contains information about selected states
invoice_list contains information about all invoice number that matches the states
measure return number of amount column when the state is in state list or invoice number in invoice list
 
bolfri_0-1671583288878.png

I hope this works for you 🙂





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

Proud to be a Super User!




Did you create the measure within the Sample table?

 

Also is your filter pictured using the dim_state table or other data?

 

I tried your method and I am getting odd results:

 

lpriceFTW_0-1671725032665.png

lpriceFTW_1-1671725072344.png

 

 

Invoice No. > 'Sample'[Invoice  No.] with the Don't Summarize option

State > 'Sample'State with the Don't Summarize option

Amount is that measure

 

I think you are using State from State table, thats why all the values are showing + Invoice number is without Dont Summarize option, what why you are seeing 20005 Invoice number that doesn't exist (its a sum of 10001 and 10004.)





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

Proud to be a Super User!




Your suggestion to use "don't summarize" fixed it. Thank you for this!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.