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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Giulia997
New Member

Use a measure like a filter

I have calculated a measure (in DAX), the measure Main Code extrct the first letter from a column table.

I need this measure in a filter. I think this formula can be simplify... 

I need to do everything in DAX, i can't edit the original dataset

 

Main Code =
VAR __DISTINCT_VALUES_COUNT = DISTINCTCOUNT('DIM_DOWNTIME'[Downtime Code])
VAR __MAX_VALUES_TO_SHOW = 1
RETURN
    IF(
        __DISTINCT_VALUES_COUNT > __MAX_VALUES_TO_SHOW,
        CONCATENATE(
            CONCATENATEX(
                TOPN(
                    __MAX_VALUES_TO_SHOW,
                    VALUES('DIM_DOWNTIME'[Downtime Code]),
                    LEFT('DIM_DOWNTIME'[Downtime Code],1),
                    ASC
                ),
                LEFT('DIM_DOWNTIME'[Downtime Code],1),
                ", ",
                LEFT('DIM_DOWNTIME'[Downtime Code],1),
                ASC
            ),
            ",  ecc."
        ),
        CONCATENATEX(
            VALUES('DIM_DOWNTIME'[Downtime Code]),
            LEFT('DIM_DOWNTIME'[Downtime Code],1),
            ", ",
            LEFT('DIM_DOWNTIME'[Downtime Code],1),
            ASC
        )
    )
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Giulia997 ,

 

 You can modify your formula like below:

Main Code1 = 
VAR __MAX_VALUES_TO_SHOW = 1
VAR __VALUES_TO_SHOW =
    TOPN (
        __MAX_VALUES_TO_SHOW,
        VALUES ( 'DIM_DOWNTIME'[Downtime Code] ),
        LEFT ( 'DIM_DOWNTIME'[Downtime Code], 1 ), ASC
    )
VAR __FIRST_LETTERS =
    CONCATENATEX (
        __VALUES_TO_SHOW,
        LEFT ( 'DIM_DOWNTIME'[Downtime Code], 1 ),
        ", "
    )
RETURN
    IF (
        DISTINCTCOUNT ( 'DIM_DOWNTIME'[Downtime Code] ) > __MAX_VALUES_TO_SHOW,
        __FIRST_LETTERS & ", ecc.",
        __FIRST_LETTERS
    )

vkongfanfmsft_0-1726820962862.png

 

Best Regards,
Adamk Kong

 

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
Anonymous
Not applicable

Hi @Giulia997 ,

 

 You can modify your formula like below:

Main Code1 = 
VAR __MAX_VALUES_TO_SHOW = 1
VAR __VALUES_TO_SHOW =
    TOPN (
        __MAX_VALUES_TO_SHOW,
        VALUES ( 'DIM_DOWNTIME'[Downtime Code] ),
        LEFT ( 'DIM_DOWNTIME'[Downtime Code], 1 ), ASC
    )
VAR __FIRST_LETTERS =
    CONCATENATEX (
        __VALUES_TO_SHOW,
        LEFT ( 'DIM_DOWNTIME'[Downtime Code], 1 ),
        ", "
    )
RETURN
    IF (
        DISTINCTCOUNT ( 'DIM_DOWNTIME'[Downtime Code] ) > __MAX_VALUES_TO_SHOW,
        __FIRST_LETTERS & ", ecc.",
        __FIRST_LETTERS
    )

vkongfanfmsft_0-1726820962862.png

 

Best Regards,
Adamk Kong

 

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

bhanu_gautam
Super User
Super User

@Giulia997 , Try this

 

Main Code =
VAR __DISTINCT_VALUES_COUNT = DISTINCTCOUNT('DIM_DOWNTIME'[Downtime Code])
VAR __MAX_VALUES_TO_SHOW = 1
RETURN
IF(
__DISTINCT_VALUES_COUNT > __MAX_VALUES_TO_SHOW,
CONCATENATE(
CONCATENATEX(
TOPN(
__MAX_VALUES_TO_SHOW,
VALUES('DIM_DOWNTIME'[Downtime Code]),
LEFT('DIM_DOWNTIME'[Downtime Code], 1),
ASC
),
LEFT('DIM_DOWNTIME'[Downtime Code], 1),
", "
),
", ecc."
),
CONCATENATEX(
VALUES('DIM_DOWNTIME'[Downtime Code]),
LEFT('DIM_DOWNTIME'[Downtime Code], 1),
", "
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Giulia997_0-1726753218964.png

I have this result

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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