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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
texmexdragon2
Helper V
Helper V

Adding a filter to a table (in DAX)

I have this table below which computes Mode.  

 

I have a calculated column that is essentially a true/false column.   I want to compute the mode for each of those choices (the true ones, and the false ones), but based on the measure below.  Just adding that column as a slicer or filter on this measure does not work.  

 

Any ideas?

 

Mode_ShippedQty =
TOPN (
1,
ADDCOLUMNS (
VALUES ( ShippedOrders2022_Query[ShippedQty] ),
"Frequency", CALCULATE (COUNT ( ShippedOrders2022_Query[ShippedQty] ) )
),
[Frequency], 0
)
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @texmexdragon2 ,

Your measure mainly used a TOPN function, which will return a row in your formula instead of a value.

I create a sample. Single or Bulk is a calculated column according to your description.

vkalyjmsft_0-1656481920060.png

In my understanding, you want to use Single or Bulk as a slicer and to calculate the Calculate the ShippedQty with the largest number of rows separately. Modify your formula to:

Mode_ShippedQty =
VAR _T =
    TOPN (
        1,
        ADDCOLUMNS (
            VALUES ( ShippedOrders2022_Query[ShippedQty] ),
            "Frequency", CALCULATE ( COUNT ( ShippedOrders2022_Query[ShippedQty] ) )
        ),
        [Frequency], 0
    )
RETURN
    MAXX ( _T, [ShippedQty] )

Get the correct result.

vkalyjmsft_1-1656482248007.png

vkalyjmsft_2-1656482261965.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @texmexdragon2 ,

Your measure mainly used a TOPN function, which will return a row in your formula instead of a value.

I create a sample. Single or Bulk is a calculated column according to your description.

vkalyjmsft_0-1656481920060.png

In my understanding, you want to use Single or Bulk as a slicer and to calculate the Calculate the ShippedQty with the largest number of rows separately. Modify your formula to:

Mode_ShippedQty =
VAR _T =
    TOPN (
        1,
        ADDCOLUMNS (
            VALUES ( ShippedOrders2022_Query[ShippedQty] ),
            "Frequency", CALCULATE ( COUNT ( ShippedOrders2022_Query[ShippedQty] ) )
        ),
        [Frequency], 0
    )
RETURN
    MAXX ( _T, [ShippedQty] )

Get the correct result.

vkalyjmsft_1-1656482248007.png

vkalyjmsft_2-1656482261965.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
tamerj1
Super User
Super User

Hi @texmexdragon2 

please try

Mode_ShippedQty =
TOPN (
1,
ADDCOLUMNS (
ALLSELECTED ( ShippedOrders2022_Query[ShippedQty] ),
"Frequency", CALCULATE (COUNT ( ShippedOrders2022_Query[ShippedQty] ) )
),
[Frequency], 0
)

@tamerj1  @Ashish_Mathur   Below is the calculated column I mentioned.    

 

My desire is to be able to have the mode calculated separately for Bulk  or  for Single.   

 

So if there are 30 rows.   I want to determine what the mode is for all of the rows that are bulk, and all of the rows that are single.    So if there was 10 rows for single, and the shipped quantity of "7" occurs on 6 out of 10 rows, then the mode would be 7.  

 

Single or Bulk =
SWITCH (
TRUE (),
 
CONTAINSSTRINGEXACT ( ShippedOrders2022_Query[Description], "40pk" ), "Bulk",
CONTAINSSTRINGEXACT ( ShippedOrders2022_Query[Description], "96PK" ), "Bulk",
"Single"
)

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.