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
Anonymous
Not applicable

Count differents values with condition

Hi, I need a help to create a colunm in DAX.

 

The colunm "How many different hour" need to count how many different hours I have per "Type", for example: 

Type A have 2 different hours (20:20:53 and 22:15:41) so the colunm "How many different hour" bring me 2.

Type B have 3 different hours (19:45:22, 08:12:00 and 12:34:56) so the colunm "How many different hour" bring me 3

 

ROWHourTypeHow many different hour
120:20:53A2
220:20:53A2
320:20:53A2
422:15:41A2
522:15:41A2
622:15:41A2
722:15:41A2
822:15:41A2
922:15:41A2
1019:45:22B3
1119:45:22B3
1208:12:00B3
1308:12:00B3
1408:12:00B3
1512:34:56B3
1612:34:56B3
1712:34:56B3

 

 Anybody can help me? 

 

Thanks a lot.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

 

Here are the steps you can follow:

1. Create calculated column.

 

Flag = 
var _table1=
SUMMARIZE('Table','Table'[Type],'Table'[Hour])
return
COUNTX(
    FILTER(_table1,
    [Type]=EARLIER('Table'[Type])),[Hour])

 

2. Result:

vyangliumsft_0-1691394457211.png

 

 

Best Regards,

Liu Yang

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

4 REPLIES 4
Anonymous
Not applicable

Hi  @Anonymous ,

 

Here are the steps you can follow:

1. Create calculated column.

 

Flag = 
var _table1=
SUMMARIZE('Table','Table'[Type],'Table'[Hour])
return
COUNTX(
    FILTER(_table1,
    [Type]=EARLIER('Table'[Type])),[Hour])

 

2. Result:

vyangliumsft_0-1691394457211.png

 

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

@Anonymous 

 

Thanks a lot.

HassanAshas
Helper V
Helper V

Not sure if this is the most efficient solution but try this as calculated column, 

 

CalculatedColumn = 

var _Value = 'Table'[Type]

var _Table = 
    FILTER(
        'Table', 
        'Table'[Type] = _Value
    )

var _Result = 
    CALCULATE(
        DISTINCTCOUNT('Table'[Hour]), 
        _Table
    )

return _Result

 

Anonymous
Not applicable

Hello @HassanAshas 

 

Doesn't work, appears this message: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

 

 

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.