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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
EZimmet
Resolver I
Resolver I

DAX DISTINCTCOUNT with filters

I’m trying to use DAX for the following two below :

I have multiple Data Centers, Devices (Servers, Switches, Ect) , within the Devices multiple Power Supplies.

After each number is established it will be pulled into a formula to calculate percentages 

 

This is a snip of part of the Data Source

Table:   "Script all connected and not connected Power Supply"

Site_NameParent_DevicePower_SupplyStatus
ABCP123PS1Connected
ABCP123PS2NotConnected
ABCP5555PS1Connected
ABCP5555PS2Connected
XYZPP223344PS1Connected
XYZPP223344PS2Connected
XYZPP223344PS3Connected
XYZPP223344PS4Connected
XYZPP8889PS1NotConnected

 

 

#1

The end result will be to count the DISTINCT Parent_Device filtered by the Site_Name & Status 

  • FILTER specific Data Center(s)
  • FILTER on Status Connected / Not Connected
  • DISTINCTCOUNT of Parent Device Num  

 

#2

The end result will be to COUNT all the Power Supplies filtered by the Site_Name & Status

  • FILTER specific Data Center(s)
  • FILTER on Status Connected / Not Connected
  • COUNTROWS all Power Supplies in the

 

 

I started looking at something like the below but need to add filters unless you can think of a better way - TY 

 

-- --------------------------------------------------------------------------------------------------------

 VAR ABC CNT Site =

    SUMX(

        DISTINCT('Script all connected and not connected Power Supply'[Site_Name] = "ABC"),

    CALCULATE(

        DISTINCTCOUNT( 'Script all connected and not connected Power Supply'[Parent_Device])

    ))

-- --------------------------------------------------------------------------------------------------------

 VAR XYZ CNT Site =

    SUMX(

        DISTINCT('Script all connected and not connected Power Supply'[Site_Name] = "XYZ"),

    CALCULATE(

        DISTINCTCOUNT( 'Script all connected and not connected Power Supply'[Parent_Device])

    ))

-- --------------------------------------------------------------------------------------------------------

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @EZimmet 

Hi @EZimmet 

If you want to get the distinct count of the values of in  a column just use DISTINCTCOUNT on that then filter it or create a virtual summarized table, filter it then counter the rows

CALCULATE (
    DISTINCTCOUNT ( 'Script all connected and not connected Power Supply'[Parent_Device] ),
    'Script all connected and not connected Power Supply'[Site_Name] = "ABC"
)


COUNTROWS (
    SUMMARIZE (
        FILTER (
            'Script all connected and not connected Power Supply',
            'Script all connected and not connected Power Supply'[Site_Name] = "ABC"
        ),
        'Script all connected and not connected Power Supply'[Parent_Device]
    )
)

**replace the filter with a different one.

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
maruthisp
Solution Sage
Solution Sage

Hi EZimmet,

I tried to implement the solution fr the above original description. Please find the attached pbix file.

DAX DISTINCTCOUNT with filters.pbix

Please let me know if there is any missing things in the pbix file.

If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too. And if you found it useful, a quick "Kudos" is always appreciated, thanks! 

 

Best Regards, 

Maruthi 

LinkedIn - http://www.linkedin.com/in/maruthi-siva-prasad/ 

X            -  Maruthi Siva Prasad - (@MaruthiSP) / X

MFelix
Super User
Super User

Hi @EZimmet 

 

For the two measure you may simple use the metrics below:

Count Power Supply = COUNTROWS('Table')

Count of Parent Device = DISTINCTCOUNT('Table'[Parent_Device])

The using the Parent_Device, Status and site name on the visual you have the context for the calculation if you add a measure similar to this you can get:

Weight = DIVIDE([Count of Parent Device], [Count Power Supply])

MFelix_1-1750717677077.png

 

You would only need to do some advance calculations if you don't want to use the columns as part of your context on the visual and want to have a specific value for each site, but if you use those columns for context simple DAX should work properly.

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



danextian
Super User
Super User

Hi @EZimmet 

Hi @EZimmet 

If you want to get the distinct count of the values of in  a column just use DISTINCTCOUNT on that then filter it or create a virtual summarized table, filter it then counter the rows

CALCULATE (
    DISTINCTCOUNT ( 'Script all connected and not connected Power Supply'[Parent_Device] ),
    'Script all connected and not connected Power Supply'[Site_Name] = "ABC"
)


COUNTROWS (
    SUMMARIZE (
        FILTER (
            'Script all connected and not connected Power Supply',
            'Script all connected and not connected Power Supply'[Site_Name] = "ABC"
        ),
        'Script all connected and not connected Power Supply'[Parent_Device]
    )
)

**replace the filter with a different one.

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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