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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
liselotte
Helper I
Helper I

Measure excluding row context

I have tables:

- dimension table dim_Model with columns Model UID, Model Name, Factory (each Model UID has 1 unique Model Name and vice versa)

- dimension table dim_Style with columns Style UID, Style Name

- fact table fact_Accessory with columns Model UID, Style UID, Accessory_UID, Is_Metallic, Year, Price

I want to create a visual table of columns Model Name, Factory, Style Name, Nr Metallic Accessories which is Distinct Count of Accessory_UID with Is_Metallic=1 for Model Name. I expect that Nr Metallic Accessories is the same for each Model Name regardless Style Name. 

I have tried these queries but they don't work:

 

 

 

nr_Metallic_Accesories_1 = CALCULATE(
    SUMX(
        SUMMARIZE('fact_Accessory','fact_Accessory'[Accessory UID],'fact_Accessory'[Is_Metallic])
        ,[Is_Metallic]
    )
    ,REMOVEFILTERS('dim_Style')
    ,FILTER(
        'fact_Accessory'
        ,'fact_Accessory'[Is_Metallic]=1
    )
)

nr_Metallic_Accessories_2 = 
var _model_uid = SELECTEDVALUE('dim_Model'[Model UID])
return
CALCULATE(
	DISTINCTCOUNT('fact_Accessory'[Accessory UID]),
    FILTER( 
        ALLSELECTED('fact_Accessory')
        ,'fact_Accessory'[Model UID] = _model_uid
        && 'fact_Accessory'[Is_Metallic]=1
    ) 
)

 

 

Could anyone help me with this, please? Thank you.

1 ACCEPTED SOLUTION

Hi @liselotte ,

 

Please try this formula:

nr_Metallic_Accessories_2 = 
IF(MAX('fact_Accessory'[Is_Metallic]) in {0,1},
CALCULATE(
	SUM('fact_Accessory'[Is_Metallic]),
	ALLEXCEPT('fact_Accessory','fact_Accessory'[Model UID])
))

 

Result:

vlinhuizhmsft_1-1732516613753.png

 

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.

View solution in original post

6 REPLIES 6
v-linhuizh-msft
Community Support
Community Support

Thanks for the replies from Poojara_D12 and PhilipTreacy.

 

Hi @liselotte ,

 

With a modification on the formula you gave, please try:

nr_Metallic_Accessories_2 =
VAR _model_uid =
    SELECTEDVALUE ( 'dim_Model'[Model UID] )
RETURN
    IF (
        MAX ( 'fact_Accessory'[Is_Metallic] ) = 1,
        CALCULATE (
            DISTINCTCOUNT ( 'fact_Accessory'[Accessory_UID] ),
            FILTER (
                ALLSELECTED ( 'fact_Accessory' ),
                'fact_Accessory'[Model UID] = _model_uid
                    && 'fact_Accessory'[Is_Metallic] = 1
            )
        )
    )

Result:

vlinhuizhmsft_0-1731652998256.png

 

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.

Hi Zhu,

Thank you for your help and sorry for my late response. Your suggested query seems to work well for the rows with Sum of Is_Metallic =1, but I expected that the second row in your screenshot should have nr_Metallic_Accessories_2=2 too. Is there any way to do that? Thank you.

Hi @liselotte ,

 

Please try this formula:

nr_Metallic_Accessories_2 = 
IF(MAX('fact_Accessory'[Is_Metallic]) in {0,1},
CALCULATE(
	SUM('fact_Accessory'[Is_Metallic]),
	ALLEXCEPT('fact_Accessory','fact_Accessory'[Model UID])
))

 

Result:

vlinhuizhmsft_1-1732516613753.png

 

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.

That works like a charm. Thank you very much! 🙂

Poojara_D12
Super User
Super User

Hi @liselotte 

To create a table showing Model Name, Factory, Style Name, and Nr Metallic Accessories with a consistent count of metallic accessories for each Model Name regardless of Style Name, you’ll want to do the following in DAX:

  1. Calculate the Distinct Count of Metallic Accessories for each Model Name with Is_Metallic = 1.
  2. Remove Filters on Style Name so that Nr Metallic Accessories is not affected by the Style dimension.

Here’s a measure that should achieve this:

 

Nr_Metallic_Accessories = 
CALCULATE(
    DISTINCTCOUNT('fact_Accessory'[Accessory UID]),
    'fact_Accessory'[Is_Metallic] = 1,
    REMOVEFILTERS('dim_Style'[Style UID]) // Removes the Style filter to avoid interference
)

 

Create a visual table with:

  • Model Name, Factory, and Style Name from your dimension tables.
  • Nr Metallic Accessories from the measure we just defined.

This measure should produce the same count of metallic accessories for each Model Name across all styles. Let me know if this approach works!

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
YouTube: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
PhilipTreacy
Super User
Super User

@liselotte 

 

Can you supply sample data please, or your PBIX file.  You'll get help quicker if we don't have to recreate the data for all the tables.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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