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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
vinicius_ramos
Helper III
Helper III

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
v-yangliu-msft
Community Support
Community Support

Hi  @vinicius_ramos ,

 

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
v-yangliu-msft
Community Support
Community Support

Hi  @vinicius_ramos ,

 

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

@v-yangliu-msft 

 

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

 

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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