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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
char23
Helper I
Helper I

Create count column visual based on column slicer and column group on x-axis

I am trying to write a measure to create a dynamic visual. I have the following table below as a single table in my file. I want the user to be able to select a month. If the user selects June. Then I want previous month to be used in the measure (This would be May since this is the since 1 + the date rank gives the group of the previous month). Then I want the measure to count the number of rows where multiple filter conditions are met. I want to count rows where Dank rank =2, Status and Previous Status = "Not Normal" and where Type = "Task". So this would return a 1 because there is only one row where all conditions are met. But I want the measure to update based on what the user selects as the current month. If the user does not select a month, then I want to show blank for the measure. Right now, I am able to get the correct count, but when I group the visual by the "Group" column on the x-axis, I get the same number for each group rather than just the count for that specific group. (Table and current dax formula I have is below). Thank you for any help on this. 

 

IDStatusDate RankPrevious StatusMonthTypeGroup
ANormal3No previous24-MarTask<0
BNormal3No previous24-MarTask1 to 5
CNot Normal3No previous24-MarTask1 to 5
DNot Normal3No Previous24-MarNot Task11 to 15
ANot Normal2Normal24-MayTask6 to 10
BNormal2Normal24-MayNot Task6 to 10 
CNormal2Not Normal24-MayNot Task6 to 10
DNot Normal2Not Normal24-MayTask6 to 10
ANot Normal1Not Normal24-JunTask1 to 5
BNot Normal1Normal24-JunTask<0
DNormal1Normal24-JunTask<0
ENormal1 24-JunTask1 to 5

 

 

Measure =

VAR SelectedMonthRank =
    CALCULATE(
        MAX('Table'[Date Rank]),
        ALLSELECTED('Table'[Month]),
        ALLSELECTED('Table'[Group]),          
        'Table'[Month] = SELECTEDVALUE('Table'[Month])
    )
VAR PreviousMonthDateRank = SelectedMonthRank + 1

VAR _tablecalculation =
    CALCULATETABLE(
        'Table',
        FILTER(
            ALL('Table'),
            'Table'[Date Rank] = PreviousMonthDateRank
            && 'Table'[Status] = "Not Normal"
            && 'Table'[Previous Status] = "Not Normal"
            && 'Table'[Type] = "Task"
    )
    )

RETURN
COUNTROWS(_tablecalculation)
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

You cannot do all this with only one table.  You need to create a disconnected table for the month slicer, and then use a measure as the filter for your original table visual.

View solution in original post

v-nuoc-msft
Community Support
Community Support

Hi @char23 

 

Thank you very much lbendlin for your prompt reply. The solution you offer is reasonable. Let me add some details here.

 

Create a new month table.

Date = 
DISTINCT(
    SELECTCOLUMNS(
        'Table',
        "Month",
        'Table'[Month].[Month]
    )
)

 

vnuocmsft_0-1723534335818.png

 

Create a measure.

 

Measure = 
var _selectMonth = SELECTEDVALUE('Date'[Month])
var _DateRank = 
CALCULATE(
    SELECTEDVALUE('Table'[Date Rank]),
    FILTER(
        ALL('Table'),
        'Table'[Month].[Month] = _selectMonth
    )
) + 1
var _tablecalculation = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        ALL('Table'),
        'Table'[Date Rank] = _DateRank
        && 
        'Table'[Status] = "Not Normal"
        && 
        'Table'[Previous Status] = "Not Normal"
        && 
        'Table'[Type] = "Task"
    )
)
RETURN _tablecalculation

 

Here is the result.

vnuocmsft_1-1723534430753.png

 

Regards,

Nono Chen

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-nuoc-msft
Community Support
Community Support

Hi @char23 

 

Thank you very much lbendlin for your prompt reply. The solution you offer is reasonable. Let me add some details here.

 

Create a new month table.

Date = 
DISTINCT(
    SELECTCOLUMNS(
        'Table',
        "Month",
        'Table'[Month].[Month]
    )
)

 

vnuocmsft_0-1723534335818.png

 

Create a measure.

 

Measure = 
var _selectMonth = SELECTEDVALUE('Date'[Month])
var _DateRank = 
CALCULATE(
    SELECTEDVALUE('Table'[Date Rank]),
    FILTER(
        ALL('Table'),
        'Table'[Month].[Month] = _selectMonth
    )
) + 1
var _tablecalculation = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        ALL('Table'),
        'Table'[Date Rank] = _DateRank
        && 
        'Table'[Status] = "Not Normal"
        && 
        'Table'[Previous Status] = "Not Normal"
        && 
        'Table'[Type] = "Task"
    )
)
RETURN _tablecalculation

 

Here is the result.

vnuocmsft_1-1723534430753.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

lbendlin
Super User
Super User

You cannot do all this with only one table.  You need to create a disconnected table for the month slicer, and then use a measure as the filter for your original table visual.

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 MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.