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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Vlad_Akka
Regular Visitor

COUNTAX DAX Formel in Power BI Desktop need explanation

Hello all.

 

I have two Lookup tables. One of it has data about learning courses (number of course, Course Start data, the quantitiy of the participants etc). The second one is a person table with learning courses in which they have participated.

The both of the tables are exported from Excelsheets.

 

"Cousrse Groups Lookup " Table

CS Course numberDate of StartDate of EndCourse activity stateParticipants QuantitiyParticipants
successful Quantitiy
KPI
104.09.202425.02.2024ended55Not used now
227.03.202408.05.2024ended2221Not used now
315.05.202415.02.2025active60Not used now

 

"Person List Lookup " Table

Personal NrPersonsCS Course numberParticipation
state
Country
1Lionel11France
2Laurence11France
3François, Vetea11France
4Sashko11France
5Vetea11France
6Schreiner21Germany
7Schneider21Germany
8Schindler21Germany
9Backenbauer21Germany
10Ivaschko21Germany
11Lindnder21Germany
12Musterman21Germany
13Musterman121Germany
14Müller21Germany
15Schmidt21Germany
16Fischer21Germany
17Weber21Germany
18Meyer21Germany
19Wagner21Germany
20Becker21Germany
21Schulz21Germany
22Bauer21Germany
23Schäfer21Germany
24Koch21Germany
25Schröder21Germany
26Neumann21Germany
27Zimmermann22Germany
28Braun 33Germany
29Krüger33Germany
30Hofmann33Germany
31Klein33Germany
32Schmitt33Germany
33Bley33Germany
34Schmitz04Germany
35Krause04Germany
36Schulze04Germany
37Schuster04Germany
38Köhler04Germany
39König04Germany
40Winter04Germany
41Schach04Germany
42Huber04Germany
43Kaiser04Germany
44Fuchs04Germany
45Peters04Germany
46Lang04Germany
47Möller04Germany
48Weiß04Germany
49Jung04Germany
50Hahn04Germany
51Schubert04Germany
52Vogel04Germany
53Vogler04Germany
54Keller04Germany
55Berger04Germany
56Winkler04Germany
57Roth04Germany
58Beck04Germany
59Schumacher04Germany
60Groß04Germany
61Seidel04Germany
62Ziegler04Germany
63Kuhn04Germany
64Bergmann04Germany
65Pfeiffer04Germany
66Novak04Czech Republic
67Noak04Czech Republic
68Pietsch04Czech Republic
69Kowalski04Czech Republic

(no worry, all names are used for example)

 

In the "Course Groups Lookup" table i have the column "Participants Quantitiy" yet. But it is calculated and prompt manually.

Every time if the new course begin, the neu column shall be added into the Table "Course Group Lookup" with recalculation, based on the data in the "Person List Lookup" Table. The both tables have one relationship 1 : x. See the figure below

 

My goal is to add the column  "Participants Quantitiy CC" with a measure, which just calculate the participants quantity for every learning course (see the figure).

2024_05_08_16_07_Model.jpg

 

 

 

 

 

2024_05_08_Tabellen.jpg

 

2024_05_08_DAX_and_measures.jpg

 

Of course i could use the DAX Formula CALCULATE with FILTER and logical conditions. But in this case i shall add the logic if a new learning course begin and this is not what i want.

 

If you will see attantively on the measure itself, and on the result in the added column, probably you will come to the same conclusion as i - it doesn´t work because i have nearly 30 persons with the course number "0" and due to the logic of the formula COUNTAX i shall have for all of the learning courses 30 persons. But you will be wery surprised because it works (see the measure below and the content of the column in the picture above).

 

EXAMPLE of Quantity =   COUNTAX ( 'Person List Lookup', 'Person List Lookup'[CS Course number] = 0 

 

There is no matter if i compare with 0 or change the condition to less as 2. The result will be the same - it works as expected.

 

 Truly says, i have no idea, but i will be appraciate to you to hear your explanations.

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Vlad_Akka ,

 

Measure and calculated columns have different row contexts, and the value of the calculated column is calculated based on the table context and is a fixed value.

Refer to:

Solved: Using a Measure in a Calculated Column - Microsoft Fabric Community

 

You may consider the following formula for calculating column dax:

Column =
COUNTX(
    FILTER(ALL('Person List Lookup'),
    'Person List Lookup'[CS Course number]=EARLIER('Cousrse Groups Lookup'[CS Course number])),'Person List Lookup'[Personal Nr])

vyangliumsft_0-1715218781879.png

This is the related document, you can view this content:

Context in DAX Formulas | Microsoft Learn

Calculated Columns and Measures in DAX - SQLBI

Column and measure references in DAX - DAX | Microsoft Learn

 

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

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Vlad_Akka ,

 

Measure and calculated columns have different row contexts, and the value of the calculated column is calculated based on the table context and is a fixed value.

Refer to:

Solved: Using a Measure in a Calculated Column - Microsoft Fabric Community

 

You may consider the following formula for calculating column dax:

Column =
COUNTX(
    FILTER(ALL('Person List Lookup'),
    'Person List Lookup'[CS Course number]=EARLIER('Cousrse Groups Lookup'[CS Course number])),'Person List Lookup'[Personal Nr])

vyangliumsft_0-1715218781879.png

This is the related document, you can view this content:

Context in DAX Formulas | Microsoft Learn

Calculated Columns and Measures in DAX - SQLBI

Column and measure references in DAX - DAX | Microsoft Learn

 

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.

Thank you for your time and for the help. It was helpful, but i am still wondering why the DAX formula in my question works

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors