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
hcze
Helper II
Helper II

Calculated measure as hierarchy

Hi,

 

I have issue trying to have matrix to show calculated measure as row header/hierarchy. Any helps will be appreciated.

 

Here is my test data and also separate standard calendar table that I dont add here

 

ClientCountryPolicyInception DateCancelation DateClaim NoClaim Date
ABCUSP115/01/2024 C013/02/2024
ABCUKP217/01/20242/02/2024  
ABCUKP320/02/2024 C035/05/2024
ABCUKP431/03/2024 C04 
ABCUKP531/03/2024 C05 
ABCUSP610/03/2024 C06 
ABCUSP71/05/2024 C0720/06/2024
ABCUKP82/05/2024 C08 
ABCUSP93/05/2024 C09 

 


and here is my expected result

 

   JanFebMarAprMayJune
Active Policy count  225080
 ABC 225080
  US112040
  UK113040
         
Claims Count  010011
 ABC 010011
  US010001
  UK000010

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @hcze ,

 

Here I create a sample to have a test.

Data Table:

vrzhoumsft_0-1727667819761.png

DimTables:

 

DimCount = 
DATATABLE(
    "Count Period",STRING,
    "Order",INTEGER,
    {
        {"Active Policy Count",1},
        {"Claims Count",2}
    })
DimDate = ADDCOLUMNS(CALENDAR(EOMONTH(MIN('Table'[Inception Date]),-1)+1,EOMONTH(MAX('Table'[Claim Date]),0)),"Year",YEAR([Date]),"MonthNo",MONTH([Date]),"Month",FORMAT([Date],"MMM"))

 

vrzhoumsft_1-1727667866754.png

Measure:

 

Measure = 
VAR _HAVEDATA =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            ALLEXCEPT('Table','Table'[Client]),
            'Table'[Inception Date] >= MIN ( DimDate[Date] )
                && 'Table'[Inception Date] <= MAX ( DimDate[Date] )
        )
    ) + 0
VAR _ActiveCount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            'Table',
            'Table'[Inception Date] <= MAX ( DimDate[Date] )
                && OR (
                    'Table'[Cancelation Date] = BLANK (),
                    'Table'[Cancelation Date] > MAX ( DimDate[Date] )
                )
        )
    ) + 0
VAR _ClaimsCount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            'Table',
            'Table'[Claim Date] >= MIN ( DimDate[Date] )
                && 'Table'[Claim Date] <= MAX ( DimDate[Date] )
        )
    ) + 0
RETURN
    SWITCH (
        MAX ( DimCount[Count Period] ),
        "Active Policy Count", IF ( _HAVEDATA = 0, 0, _ActiveCount ),
        "Claims Count", _ClaimsCount
    )

 

Result is as below.

vrzhoumsft_3-1727668233780.png

 

Best Regards,
Rico 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

2 REPLIES 2
Anonymous
Not applicable

Hi @hcze ,

 

Here I create a sample to have a test.

Data Table:

vrzhoumsft_0-1727667819761.png

DimTables:

 

DimCount = 
DATATABLE(
    "Count Period",STRING,
    "Order",INTEGER,
    {
        {"Active Policy Count",1},
        {"Claims Count",2}
    })
DimDate = ADDCOLUMNS(CALENDAR(EOMONTH(MIN('Table'[Inception Date]),-1)+1,EOMONTH(MAX('Table'[Claim Date]),0)),"Year",YEAR([Date]),"MonthNo",MONTH([Date]),"Month",FORMAT([Date],"MMM"))

 

vrzhoumsft_1-1727667866754.png

Measure:

 

Measure = 
VAR _HAVEDATA =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            ALLEXCEPT('Table','Table'[Client]),
            'Table'[Inception Date] >= MIN ( DimDate[Date] )
                && 'Table'[Inception Date] <= MAX ( DimDate[Date] )
        )
    ) + 0
VAR _ActiveCount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            'Table',
            'Table'[Inception Date] <= MAX ( DimDate[Date] )
                && OR (
                    'Table'[Cancelation Date] = BLANK (),
                    'Table'[Cancelation Date] > MAX ( DimDate[Date] )
                )
        )
    ) + 0
VAR _ClaimsCount =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Policy] ),
        FILTER (
            'Table',
            'Table'[Claim Date] >= MIN ( DimDate[Date] )
                && 'Table'[Claim Date] <= MAX ( DimDate[Date] )
        )
    ) + 0
RETURN
    SWITCH (
        MAX ( DimCount[Count Period] ),
        "Active Policy Count", IF ( _HAVEDATA = 0, 0, _ActiveCount ),
        "Claims Count", _ClaimsCount
    )

 

Result is as below.

vrzhoumsft_3-1727668233780.png

 

Best Regards,
Rico Zhou

 

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

Selva-Salimi
Super User
Super User

Hi @hcze 

 

you should create another table add these two phrase "Active Policy count" and "Claim counts" in that with Id's 1 and 2 to manage. add the column of phrase in your visual matrix and then client from your table and then write a measure as follows:

 

if ( selectedvalue ([ID] =1 , [measure to calculate active policy count] , if (selectedvalue ([ID]=2 , [measure to calculate claim counts], 0))

 

add this measure to the value of your matrix.

 

If this post helps, then I would appreciate a thumbs up 👍 and mark 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.