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
maximik
Frequent Visitor

How to count rows based on two criteria?

Hi all,

I am building my first PowerBI project and so far it works great.

Unfortunately, I know stumbled on a big problem and I am unsure on how to solve it.

 

I have a gigantic table, it looks sth like the table below.

It contains the name of an Azure Scale Set, the number of the child VM or instance within that scale set, the maximum CPU performance and the time stamp (datetime).

What I would like to do is to  display them in a graph, so you can click in a table e.g. on ScaleSet1 and you can see the CPU over time, in combination with the amount of underlying VMs. The kicker would be, if all "Max CPU performance" values of 0 are filtered out (as they cost no money), scaling is done via AKS, so no autoscale.

 

I guess what I need to do to get there:

- Calculate the number of instances per scale set (column 1) per hour (column 4) while filtering out "0" values.

- Then I have to plot it in a table, maybe with two Y-axis, one for CPU, and the other one for the number of VMs>0.

 

I am completely lost though how to tackle it.

Are there any ideas?

 

Virtual Machine Scale SetVM/Instance in that scale SetMax CPU performanceTime stamp (Date column)
ScaleSet1ScaleSet1_VM1501.01.2023_3pm
ScaleSet1ScaleSet1_VM21001.01.2023_3pm
ScaleSet1ScaleSet1_VM3001.01.2023_3pm
ScaleSet1ScaleSet1_VM12001.01.2023_4pm
ScaleSet1ScaleSet1_VM23001.01.2023_4pm
ScaleSet1ScaleSet1_VM31001.01.2023_4pm
ScaleSet2ScaleSet2_VM1501.01.2023_3pm
ScaleSet2ScaleSet2_VM21001.01.2023_3pm
ScaleSet2ScaleSet2_VM32001.01.2023_3pm
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @maximik 

1.You can create a slicer table

Slicer = {"Counts","Counts>0"}

2.Then create a measure

Counts =
IF (
    OR (
        ISFILTERED ( Slicer[Value] ) = FALSE (),
        SELECTEDVALUE ( Slicer[Value] ) = "Counts"
    ),
    CALCULATE ( COUNTA ( 'Table'[VM/Instance in that scale Set] ) ),
    IF (
        SELECTEDVALUE ( Slicer[Value] ) = "Counts>0",
        CALCULATE (
            COUNTA ( 'Table'[VM/Instance in that scale Set] ),
            FILTER ( 'Table', [Max CPU performance] > 0 )
        )
    )
)

3.Then create a column visual, put the time to the x-axis, and put the measure to y-axis, then put the virtual to legend, and put the value of slicer table to a slicer.

Output

vxinruzhumsft_0-1696991058993.png

 

vxinruzhumsft_1-1696991069606.png

Best Regards!

Yolo Zhu

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

1 REPLY 1
Anonymous
Not applicable

Hi @maximik 

1.You can create a slicer table

Slicer = {"Counts","Counts>0"}

2.Then create a measure

Counts =
IF (
    OR (
        ISFILTERED ( Slicer[Value] ) = FALSE (),
        SELECTEDVALUE ( Slicer[Value] ) = "Counts"
    ),
    CALCULATE ( COUNTA ( 'Table'[VM/Instance in that scale Set] ) ),
    IF (
        SELECTEDVALUE ( Slicer[Value] ) = "Counts>0",
        CALCULATE (
            COUNTA ( 'Table'[VM/Instance in that scale Set] ),
            FILTER ( 'Table', [Max CPU performance] > 0 )
        )
    )
)

3.Then create a column visual, put the time to the x-axis, and put the measure to y-axis, then put the virtual to legend, and put the value of slicer table to a slicer.

Output

vxinruzhumsft_0-1696991058993.png

 

vxinruzhumsft_1-1696991069606.png

Best Regards!

Yolo Zhu

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

 

 

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.