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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Tjordaske85
Frequent Visitor

Count in function of other filters

At the left you'll find a simple table, at the right you'll find the tables I want to create in Power BI:

Tjordaske85_0-1666249483956.png

 

First a small explanation of the left table:

- You'll see that project 'Building A' is started in august when the first List is filled in.

- Every time a list of a certain ListTempNr is filled in, the ListNr goes 1 up. The ListNr for every project starts from 0, even when they are using the same ListTempNr.

 

At the right you'll find in column G and H some ordinary filter options I'm going to create in Power BI.

So one to select the Month and one to select the ListTempNr

 

First Question: how to create with a DAX-formula column '#ListNr'. This value is the count of unique ListNr according the selected Month and ListTempNr?

 

In the table at the bottom right there is a KPI. This is "OK" if the "#ListNr" for the current Month and ListTempNr = A is greater than 0, else it is "NOK". Second Question: How to create this with a DAX-formula?

 

My current knowledge of DAX is 0. I'm going to follow a course but in the meantime I want to start creating some basic dashboards. Thanks in advance!!

 

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

Hi  @Tjordaske85 ,

Here are the steps you can follow:

1. In Power query. Add Column – Index Column – From 1.

vyangliumsft_0-1666324846991.png

2. Create calculated column.

Flag =
var _min=
MINX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[Creation date]=EARLIER('Table'[Creation date])),[Index])
var _if=
IF(
    'Table'[Index]=_min,1,0)
return
_if
ListNr =
SUMX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[ListTempNr]=EARLIER('Table'[ListTempNr])
&&'Table'[Index]<=EARLIER('Table'[Index])),[Flag])
QuestionNr =
RANKX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[ListTempNr]=EARLIER('Table'[ListTempNr])
&&'Table'[Creation date]=EARLIER('Table'[Creation date]))
,[Index],,ASC)
Month =
MONTH('Table'[Creation date])

vyangliumsft_1-1666324846994.png

3. Create calculated table.

TempNr =
DISTINCT('Table'[ListTempNr])

vyangliumsft_2-1666324846996.png

Month_Slicer =
DISTINCT('Table'[Month])

vyangliumsft_3-1666324846998.png

4. Create measure.

# ListNr =
var _selectMonth=SELECTEDVALUE('Month_Slicer'[Month])
var _selectTermNr=SELECTEDVALUE('TempNr'[ListTempNr])
var _value=
CALCULATE(DISTINCTCOUNT('Table'[ListNr]),FILTER(ALL('Table'),
'Table'[Projectname]=MAX('Table'[Projectname])&&'Table'[Month] = _selectMonth&&'Table'[ListTempNr]=_selectTermNr))
return
IF(
    _value=BLANK(),0,_value)
Okay =
IF(
    [# ListNr] =0,"No","Yes")
KPI =
var _selectMonth=SELECTEDVALUE('Month_Slicer'[Month])
var _selectTermNr=SELECTEDVALUE('TempNr'[ListTempNr])
var _value=
SUMMARIZE('Table','Table'[Projectname],"if",
CALCULATE(DISTINCTCOUNT('Table'[ListNr]),FILTER(ALL('Table'),
'Table'[Projectname]=MAX('Table'[Projectname])&&'Table'[Month] = _selectMonth&&'Table'[ListTempNr]=_selectTermNr)))
var _if=
FILTER(_value,[if]>=1)
return
IF(
MAX('Table'[Projectname]) in SELECTCOLUMNS(_if,"if1",[Projectname]),"OK","NOK")

5. Result:

vyangliumsft_4-1666324847000.png

 

If you need pbix, please click here.

 

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

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Tjordaske85 ,

Creating a calculation table acts as the main function of Slicer, which has no direct relationship with the data in the main table, and will affect the display of data in the main table through the creation of Measure.

 

If you directly use Month and ListTempNr of the main table as Slicer, such as Month=October, ListTempNr=B, in this case there is no Building C, it will not be displayed directly.

 

If you are the current month and a fixed list, you can modify to the following function:

KPI =
var _value=
SUMMARIZE('Table','Table'[Projectname],"if",
CALCULATE(DISTINCTCOUNT('Table'[ListNr]),FILTER(ALL('Table'),
'Table'[Projectname]=MAX('Table'[Projectname])&&'Table'[Month] = MONTH(TODAY()) &&'Table'[ListTempNr]="A")))
var _if=
FILTER(_value,[if]>=1)
return
IF(
MAX('Table'[Projectname]) in SELECTCOLUMNS(_if,"if1",[Projectname]),"OK","NOK")

 

 

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.

Tjordaske85
Frequent Visitor

Hi @v-yangliu-msft,

Thank you for helping me out!!

1. Do I need to create those calculated tables? I'm going to use the basic filters to select the Month and ListTempNr, so can't the '#ListNr' not calculate his value based on those filters?

Tjordaske85_0-1666360106276.png

 

2. The DAX-formula for the KPI also take into account the variables '_selectMonth' and '_selectTermNr'. This needs to be always the current Month and a fixed ListTempNr. How does this change the DAX-formula?

 

Again! Thanks you already very very much!!!

 

v-yangliu-msft
Community Support
Community Support

Hi  @Tjordaske85 ,

Here are the steps you can follow:

1. In Power query. Add Column – Index Column – From 1.

vyangliumsft_0-1666324846991.png

2. Create calculated column.

Flag =
var _min=
MINX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[Creation date]=EARLIER('Table'[Creation date])),[Index])
var _if=
IF(
    'Table'[Index]=_min,1,0)
return
_if
ListNr =
SUMX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[ListTempNr]=EARLIER('Table'[ListTempNr])
&&'Table'[Index]<=EARLIER('Table'[Index])),[Flag])
QuestionNr =
RANKX(FILTER(ALL('Table'),'Table'[Projectname]=EARLIER('Table'[Projectname])&&'Table'[ListTempNr]=EARLIER('Table'[ListTempNr])
&&'Table'[Creation date]=EARLIER('Table'[Creation date]))
,[Index],,ASC)
Month =
MONTH('Table'[Creation date])

vyangliumsft_1-1666324846994.png

3. Create calculated table.

TempNr =
DISTINCT('Table'[ListTempNr])

vyangliumsft_2-1666324846996.png

Month_Slicer =
DISTINCT('Table'[Month])

vyangliumsft_3-1666324846998.png

4. Create measure.

# ListNr =
var _selectMonth=SELECTEDVALUE('Month_Slicer'[Month])
var _selectTermNr=SELECTEDVALUE('TempNr'[ListTempNr])
var _value=
CALCULATE(DISTINCTCOUNT('Table'[ListNr]),FILTER(ALL('Table'),
'Table'[Projectname]=MAX('Table'[Projectname])&&'Table'[Month] = _selectMonth&&'Table'[ListTempNr]=_selectTermNr))
return
IF(
    _value=BLANK(),0,_value)
Okay =
IF(
    [# ListNr] =0,"No","Yes")
KPI =
var _selectMonth=SELECTEDVALUE('Month_Slicer'[Month])
var _selectTermNr=SELECTEDVALUE('TempNr'[ListTempNr])
var _value=
SUMMARIZE('Table','Table'[Projectname],"if",
CALCULATE(DISTINCTCOUNT('Table'[ListNr]),FILTER(ALL('Table'),
'Table'[Projectname]=MAX('Table'[Projectname])&&'Table'[Month] = _selectMonth&&'Table'[ListTempNr]=_selectTermNr)))
var _if=
FILTER(_value,[if]>=1)
return
IF(
MAX('Table'[Projectname]) in SELECTCOLUMNS(_if,"if1",[Projectname]),"OK","NOK")

5. Result:

vyangliumsft_4-1666324847000.png

 

If you need pbix, please click here.

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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