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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
johnpjustus
Helper IV
Helper IV

Count DAX function

All,

 

I have a table like this with sample data

I wanted to display some KPI values in a Card visualization.

Example : Count of records where status = Closed  and so on.

Also I would like to keep a slicer for Checklist name only with Year by removing the LCA Inspection so users can slice on the year of the check list name.

Can some one please help me to achieve this? 

Inspection dateSiteChecklist nameStatus
3/16/2024MemphisLCA Inspection - February 2024Closed
3/17/2024YorkLCA Inspection - February 2024Action in Progress
3/18/2024ToledoLCA Inspection - February 2024Pending inspection
3/19/2024PerrisLCA Inspection - February 2024Under inspection
4/15/2024MemphisLCA Inspection - March 2024Closed
4/16/2024YorkLCA Inspection - March 2024Action in Progress
4/17/2024ToledoLCA Inspection - March 2024Pending inspection
4/18/2024PerrisLCA Inspection - March 2024Under inspection

 

Thank you,

John

1 ACCEPTED SOLUTION
_AAndrade
Super User
Super User

Hi @johnpjustus,

Here is my solution:
1. KPI Cards:

_AAndrade_0-1713882584492.png


I'm using this two measures:

Count Closed = 
    CALCULATE(
        COUNTROWS(T_DataKpi),
        T_DataKpi[Status] = "Closed"
    )


Count In Progress = 
    CALCULATE(
        COUNTROWS(T_DataKpi),
        T_DataKpi[Status] = "Action in Progress"
    )


2. Checklist name only with Year

I add a new column on power query, that only returns de last 4 characters of Checklist name.

I'm using this M script:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBRC4IwEMe/ytizQklZPYoQBAVC9RDiw3KHDm2T23zo22e6ILGRTxu3+/9u90tTepC6gdwIJQlnBqhHz6I/4hLyqhbaEMkefd0w02qaeSldhv6JYVc7waMphe5uxzgiXyyf7OGOLcMnCRbB6s2rlQY+xDc2flNYzclGw4OQJEFVIGj7ja3lXFQNXM0hJSC5kEWH+jQNpJ0lJYA4b5+r5IATztqPmj9iukF5+ctKaLMuK6OgS8nGQtxKRhiXj63FuH2MMFMZ2Qs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Inspection date", type date}}),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "ChecklistName", each Text.End([Checklist name], 4), type text)
in
    #"Inserted Text After Delimiter"


This is the part of the M code that add a new column only with the Year.
#"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "ChecklistName", each Text.End([Checklist name], 4), type text)

In your code, you need to change #"Changed Type" to the name of your previous step.










Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

11 REPLIES 11
_AAndrade
Super User
Super User

Hi @johnpjustus,

Here is my solution:
1. KPI Cards:

_AAndrade_0-1713882584492.png


I'm using this two measures:

Count Closed = 
    CALCULATE(
        COUNTROWS(T_DataKpi),
        T_DataKpi[Status] = "Closed"
    )


Count In Progress = 
    CALCULATE(
        COUNTROWS(T_DataKpi),
        T_DataKpi[Status] = "Action in Progress"
    )


2. Checklist name only with Year

I add a new column on power query, that only returns de last 4 characters of Checklist name.

I'm using this M script:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBRC4IwEMe/ytizQklZPYoQBAVC9RDiw3KHDm2T23zo22e6ILGRTxu3+/9u90tTepC6gdwIJQlnBqhHz6I/4hLyqhbaEMkefd0w02qaeSldhv6JYVc7waMphe5uxzgiXyyf7OGOLcMnCRbB6s2rlQY+xDc2flNYzclGw4OQJEFVIGj7ja3lXFQNXM0hJSC5kEWH+jQNpJ0lJYA4b5+r5IATztqPmj9iukF5+ctKaLMuK6OgS8nGQtxKRhiXj63FuH2MMFMZ2Qs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Inspection date", type date}}),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "ChecklistName", each Text.End([Checklist name], 4), type text)
in
    #"Inserted Text After Delimiter"


This is the part of the M code that add a new column only with the Year.
#"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "ChecklistName", each Text.End([Checklist name], 4), type text)

In your code, you need to change #"Changed Type" to the name of your previous step.










Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thank you much!!

I need a small adjustment, actually I need the month as well, like March 2024 and so on from the M script.

 

Also, the card is displaying as Blank when I put the count closed dax. 

The card displays blank only when I select something from the checklistname slicer and another slicer called operatingEntityGroup, like below:

 

If I unselect these slicers then the dax works and the card displays data. I guess the card displays the  complete count of status = closed in the table. But I want the count to be dynamically displayed based upon the selection from the slicers. Is it possible?

 

johnpjustus_0-1713886921734.png

 

Thanks,

John

 

Do you have data for the filter applied?

You could not have closed status...

If you can Share and pbix or more pictures so I can take a look





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




The count works, for those filters applied there is no data and thats why the card displayed as Blank.

However, for other filters, the count is displaying wrong, it just displays the complete records where status is closed and not taking the filter data.

 

Also, is it possible to get the updated M code to extract Month and year from ChecklistName?

 

Thank you,

John

It looks like the problem is after adding the new column using M-code, the number of records kind of doubling and thats why the count displays wrong..

@johnpjustus,

To have a column with Month and Year use this script on Power Query:

_AAndrade_0-1713891417721.png

Table.AddColumn(#"Inserted Text After Delimiter", "Month_Year", each Text.AfterDelimiter([Checklist name], " - "), type text)

Change #"Inserted Text After Delimiter" to the name of your previous step. The output would be this:

_AAndrade_1-1713891497225.png

 

With this data set (is taken from you example) if I select February 2024 from my slicer my card visual show me 1 Closed and 1 In progress and that are the correct answers. See this image:

_AAndrade_2-1713891637657.png

I don't know what is going wrong with your data set. In order to help you, I need more information and the better way is a pbix file with same data if it's possible to you.







Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi Andrade - Sorry for coming back again. Forgot to ask before.

So I have an requirement like this, please see the screen shot below.

 

I have attached the data here and is it possible to achieve this format in PBI?

The first field is Column E in the spread sheet. Score is calculation based upon the results (Answer field in the spread sheet) in the next 3 fields.  

 

I don't have an option to attach the spread sheet, any idea as to how I can attach spread sheet?

 

johnpjustus_0-1713900335793.png

 

I don't think I woud be able to attach excel, so here is the sample data.

 

johnpjustus_1-1713901399322.png

 

Hi @johnpjustus ,

Please open a new ticket and take a look at this post:
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1717...

It can help you publish your example easily.





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thank you so much and I will go over the post.

Thank you so much, I will continue to do some testing and modify the M-code accordingly.

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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