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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Infinifox
Frequent Visitor

Help with counting rows based on conditions

Hi Everyone, 

 

I have a problem that I need help with. What I am trying to do is have 2 counts that can also be displayed within a table with these fields Work Order, Work Order Phase, Asset Tag, Count of Serialized Assets, Count of Child Assets.

 

An example of the data would be

Work OrderWork Order PhaseAsset TagAsset Type# of Serialized Assets (legislated)# of Child Assets (legislated)
2024101000111SERIALIZED10
2024101000212SYSTEM01
2024101000313SERIALIZED10
2024101000413SERIALIZED10
2024101000424SYSTEM02

 

I have a WorkOrder table that is tied to the Asset table via Asset Tag. The Asset table is tied to ChildAssets and AssetDetails via Asset Tag

 

Infinifox_0-1728581335805.png

 

Infinifox_1-1728581346740.png

 

 

Infinifox_4-1728581374044.png

 

The first count is trying to count how many assets are serialized. If Asset[Asset Type] = "SERIALIZED" and Asset Legislated[Asset Legislated] = "Y" then count that row.

 

The 2nd count is trying to count if Asset[Asset Type] = "SYSTEM" then we instead need to count how many childrows there are in Child Assets that are also Asset Legislated[Asset Legislated] = "Y".

 

I have an example of the data as a .pbix but not sure how to share it.

 

1 ACCEPTED SOLUTION

Hi @Infinifox ,

I create three tables as you mentioned.

vyilongmsft_0-1728877960523.png

Then I think you can create a measure and here is the DAX code.

Measure = 
VAR SystemAssets =
    FILTER ( Asset, Asset[assetType] = "System" )
VAR ChildAssets =
    CALCULATETABLE (
        SUMMARIZE ( ChildAsset, ChildAsset[childAssetTag], ChildAsset[assetTag] ),
        SystemAssets
    )
RETURN
    COUNTROWS ( SystemAssets )

vyilongmsft_1-1728878122510.png

 

 

Best Regards

Yilong Zhou

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

3 REPLIES 3
Infinifox
Frequent Visitor

In my example I do not have the # of serialized assets (legislated) and # of child assets (legislated) as fields. These are the fields that would be created with the measure.

 

What has to happen if an asset is SYSTEM is that I then need to go to the ChildAsset table and see what Assets are associated with that main asset. I then need to take the ChildAsset[Child Asset Tag] and then use its relationship to see if it is legislated and include it in the count.

 

In my example above the Work Order 2024101004 has 2 child assets that are legislated because the asset tag is 4. Asset tag 4 is a system in the Asset table so we need to go to the ChildAsset table. In the ChildAsset table there is 2 assets associated with that asset tag so we now need to go check both individually against the AssetDetails table to see if they are LEGISLATED = "Y"

This is the measure I was trying to use previously:

Count of Legislated Component Assets =
CALCULATE(
    COUNTROWS(
        SUMMARIZE(
            AssetChild,
            AssetChild[assetTag],  -- Grouping by assetTag
            "GroupedRows", COUNT(AssetChild[childAssetTag])
        )
    ),
        USERELATIONSHIP(AssetChild[childAssetTag], MasterAsset[assetTag]),
        AssetDetails[Legislated] = "Y"
)

Hi @Infinifox ,

I create three tables as you mentioned.

vyilongmsft_0-1728877960523.png

Then I think you can create a measure and here is the DAX code.

Measure = 
VAR SystemAssets =
    FILTER ( Asset, Asset[assetType] = "System" )
VAR ChildAssets =
    CALCULATETABLE (
        SUMMARIZE ( ChildAsset, ChildAsset[childAssetTag], ChildAsset[assetTag] ),
        SystemAssets
    )
RETURN
    COUNTROWS ( SystemAssets )

vyilongmsft_1-1728878122510.png

 

 

Best Regards

Yilong Zhou

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

v-yilong-msft
Community Support
Community Support

Hi @Infinifox ,

For some new community members, they don't have the permission to upload .pbix files. You may need to share file links via DropBox, One Drive, Drive or any other tool.

 

I also create a table as you mentioned.

vyilongmsft_0-1728614010369.png

Then I think you can use the DAX codes below.

Measure = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    'Table'[Asset Type] = "SERIALIZED",
    'Table'[# of Serialized Assets (legislated)] = 1
)
Measure 2 = 
CALCULATE (
    COUNTROWS ( 'Table' ),
    'Table'[Asset Type] = "SYSTEM",
    'Table'[# of Serialized Assets (legislated)] = 0,
    'Table'[# of Child Assets (legislated)] <> 0
)

vyilongmsft_1-1728614185744.png

 

 

 

Best Regards

Yilong Zhou

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.