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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
vnqt
Helper V
Helper V

Create custom column in a table

Hello, 

I have the data as below : 

categorySub CategoryHostModel
APTTYV1VCL_MU_FGTHost 1C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 2C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 3C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 4C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 5C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 6C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 7C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 8C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 9C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 10C4580_Ec7502_1_32
APTTYV1VCL_MU_FGTHost 11D4000_c7502_1_32
APTTYV1VCL_MU_FGTHost 12D4000_c7502_1_32
APTTYV1VCL_MU_FGTHost 13D4000_c7502_1_32
APTTYV1VCL_MU_FGTHost 14D4000_c7502_1_32
APTTYV1VCL_MU_FGTHost 15D4000_c7502_1_32
APTTYV1VCL_MU_FGTHost 16R2000_c7502_1_32
APTTYV1VCL_MU_FGTHost 17R2000_c7502_1_32
APTTYV1VCL_MU_FGTHost 18R2000_c7502_1_32
APTTYV1VCL_MU_FGTHost 19R2000_c7502_1_32
APTTYV1VCL_MU_FGTHost 20R2000_c7502_1_32
APTTYV1NCL_MU_F30Host 21C4580_Ec7502_1_32
APTTYV1NCL_MU_F30Host 22A2000_c7502_1_32
APTTYV1NCL_MU_F30Host 23A2000_c7502_1_32
APTTYV1NCL_MU_F30Host 24A2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 25C4580_Ec7502_1_32
APTTYV1BVCL_RG_AZEHost 26C4580_Ec7502_1_32
APTTYV1BVCL_RG_AZEHost 27A2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 28A2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 29A2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 30R2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 31R2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 32R2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 33R2000_c7502_1_32
APTTYV1BVCL_RG_AZEHost 34E2030_c7502_1_32

 

I would like to create the table/Matrix as below:

categorySub CategoryNumber of ModelNb VMVM WindowsVM LinuxVM otherNb HostModel 1Nb HostModel 2Nb HostModel 3Nb HostModel 4Nb Host
APTTYV1VCL_MU_FGT372007101020C4580_Ec7502_1_3210D4000_c7502_1_325R2000_c7502_1_325  
APTTYV1NCL_MU_F30220020170104C4580_Ec7502_1_321A2000_c7502_1_323    
APTTYV1BVCL_RG_AZE4200201701010C4580_Ec7502_1_322A2000_c7502_1_323R2000_c7502_1_324E2030_c7502_1_321

 

1. The columns "Model 1, 2, 3 ,4 " is the list of avalaible models of each "Sub-category"

2. "Nb Host" is total of  Host of each Model

 

Could you please advise? 

 

Thank you in advance.

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @vnqt ,

Please create below measure, and add it to table visual.

Number of Model =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
    )
RETURN
    DISTINCTCOUNT ( [Model] )
Model 1 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
    )
RETURN
    MAXX ( tmp, [Model] )
Nb Host For Model 1 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 1]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    COUNTROWS ( tmp )
Model 2 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
    )
RETURN
    MAXX ( tmp, [Model] )
Nb Host For Model 2 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 2]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    COUNTROWS ( tmp )
Model 3 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR pre_model2 = [Model 2]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
            && 'Table'[Model] <> pre_model2
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), MAXX ( tmp, [Model] ) )
Nb Host For Model 3 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 3]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), COUNTROWS ( tmp ) )
Model 4 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR pre_model2 = [Model 2]
VAR pre_model3 = [Model 3]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
            && 'Table'[Model] <> pre_model2
            && 'Table'[Model] <> pre_model3
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), MAXX ( tmp, [Model] ) )
Nb Host For Model 4 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 4]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), COUNTROWS ( tmp ) )

vbinbinyumsft_0-1663060759275.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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

5 REPLIES 5
Anonymous
Not applicable

Hi @vnqt ,

Please create below measure, and add it to table visual.

Number of Model =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
    )
RETURN
    DISTINCTCOUNT ( [Model] )
Model 1 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
    )
RETURN
    MAXX ( tmp, [Model] )
Nb Host For Model 1 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 1]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    COUNTROWS ( tmp )
Model 2 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
    )
RETURN
    MAXX ( tmp, [Model] )
Nb Host For Model 2 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 2]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    COUNTROWS ( tmp )
Model 3 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR pre_model2 = [Model 2]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
            && 'Table'[Model] <> pre_model2
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), MAXX ( tmp, [Model] ) )
Nb Host For Model 3 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 3]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), COUNTROWS ( tmp ) )
Model 4 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR pre_model1 = [Model 1]
VAR pre_model2 = [Model 2]
VAR pre_model3 = [Model 3]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] <> pre_model1
            && 'Table'[Model] <> pre_model2
            && 'Table'[Model] <> pre_model3
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), MAXX ( tmp, [Model] ) )
Nb Host For Model 4 =
VAR cur_category =
    SELECTEDVALUE ( 'Table'[category] )
VAR cur_sub_category =
    SELECTEDVALUE ( 'Table'[Sub Category] )
VAR cur_model = [Model 4]
VAR tmp =
    FILTER (
        ALL ( 'Table' ),
        'Table'[category] = cur_category
            && 'Table'[Sub Category] = cur_sub_category
            && 'Table'[Model] = cur_model
    )
RETURN
    IF ( ISEMPTY ( tmp ), BLANK (), COUNTROWS ( tmp ) )

vbinbinyumsft_0-1663060759275.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous 

 

Thank you for your solution, it works well until I filter  by Catagory. This slicer uses Catagory column in another table which has the relation with this table. 

 

When I apply the filter, the Model is empty but all other columns have value:

 

vnqt_0-1663072519844.png

How could I replace the column Category of other table in all the measures that we've just created? 

 

MAny thanks in advance. 

 

@Anonymous 

Could you please advise how to add the total of HOST of each model ? 

vnqt_0-1663077486800.png

I have another column name CPO as below, could you help to calculate the sum of CPO of each Model ? 

 

categorySub CategoryHostModelcpO

APTTYV1VCL_MU_FGTHost 1C4580_Ec7502_1_322
APTTYV1VCL_MU_FGTHost 2C4580_Ec7502_1_323
APTTYV1VCL_MU_FGTHost 3C4580_Ec7502_1_324
APTTYV1VCL_MU_FGTHost 4C4580_Ec7502_1_321
APTTYV1VCL_MU_FGTHost 5C4580_Ec7502_1_322
APTTYV1VCL_MU_FGTHost 6C4580_Ec7502_1_3233
APTTYV1VCL_MU_FGTHost 7C4580_Ec7502_1_322
APTTYV1VCL_MU_FGTHost 8C4580_Ec7502_1_326
APTTYV1VCL_MU_FGTHost 9C4580_Ec7502_1_328
APTTYV1VCL_MU_FGTHost 10C4580_Ec7502_1_3212
APTTYV1VCL_MU_FGTHost 11D4000_c7502_1_329
APTTYV1VCL_MU_FGTHost 12D4000_c7502_1_328
APTTYV1VCL_MU_FGTHost 13D4000_c7502_1_3214
APTTYV1VCL_MU_FGTHost 14D4000_c7502_1_322
APTTYV1VCL_MU_FGTHost 15D4000_c7502_1_323
APTTYV1VCL_MU_FGTHost 16R2000_c7502_1_324
APTTYV1VCL_MU_FGTHost 17R2000_c7502_1_3222
APTTYV1VCL_MU_FGTHost 18R2000_c7502_1_3224
APTTYV1VCL_MU_FGTHost 19R2000_c7502_1_3233
APTTYV1VCL_MU_FGTHost 20R2000_c7502_1_322
APTTYV1NCL_MU_F30Host 21C4580_Ec7502_1_3212
APTTYV1NCL_MU_F30Host 22A2000_c7502_1_3212
APTTYV1NCL_MU_F30Host 23A2000_c7502_1_3212
APTTYV1NCL_MU_F30Host 24A2000_c7502_1_328
APTTYV1BVCL_RG_AZEHost 25C4580_Ec7502_1_3212
APTTYV1BVCL_RG_AZEHost 26C4580_Ec7502_1_329
APTTYV1BVCL_RG_AZEHost 27A2000_c7502_1_328
APTTYV1BVCL_RG_AZEHost 28A2000_c7502_1_3214
APTTYV1BVCL_RG_AZEHost 29A2000_c7502_1_322
APTTYV1BVCL_RG_AZEHost 30R2000_c7502_1_323
APTTYV1BVCL_RG_AZEHost 31R2000_c7502_1_324
APTTYV1BVCL_RG_AZEHost 32R2000_c7502_1_3222
APTTYV1BVCL_RG_AZEHost 33R2000_c7502_1_3224
APTTYV1BVCL_RG_AZEHost 34E2030_c7502_1_3233

 

Thank you in advance. 

vnqt
Helper V
Helper V

Hi @Greg_Deckler 

 

I guess I wasn't clear enough. 

 

The columns I would like to add is in blue and orange .

- The available model listed in the columns Model 1, Model 2, Model 3, Model 4 . Normally a Sub-category has max 4 model

- The number of host of each Sub-category by Model

Greg_Deckler
Community Champion
Community Champion

@vnqt Try:

Number of Models Measure = 
  COUNTROWS(DISTINCT(SELECTCOLUMNS('Table',"category",[category],"subcategory",[Sub Category],"model",[Model])))


Nb VM Measure = COUNTROWS(DISTINCT('Table'))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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