cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors