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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rpinxt
Solution Sage
Solution Sage

Use a measure as column in a matrix

I have this data (more colums but these matter for the matrix) with a measure "Flag" with help of @v-rzhou-msft 

rpinxt_0-1712220437342.png

As said Flag is a measure but I want to make a matrix in which I want to see the % Late and on Time based on the quantity.

Something like :

rpinxt_1-1712220525791.png

So in the columns I would like to split Qty to "Late" and "On Time".

Then I could show quantity as a percentage and I would have the split that we want.

Also in the rows we probably would like to put shipmentnr and delivery document to split even into more detail.

 

But the column will not accept the measure "Flag" as input.

 

Below a sample set with data from 3 months for testing:

PeriodShipmentNrDelivery Document NumberQtyHourDiffFlag
Jan-241831178084278424751.57On Time
Jan-241831178084278520702.05On Time
Jan-241831178084278624752.67On Time
Jan-241831178084278722351.38On Time
Jan-241831178084278824751.32On Time
Jan-241831178084279924752.45On Time
Jan-24183118808428581305.18On Time
Jan-24183118808428593472.52On Time
Jan-24183118808428602803.28On Time
Jan-24183118808428612405.4On Time
Jan-24183118808428641235.17On Time
Jan-24183118808428651491.88On Time
Jan-24183118808428661202.62On Time
Jan-24183118808428672404.87On Time
Jan-241831188084287211502.48On Time
Jan-241865338084772818024.65Late
Jan-241865338084773118024.67Late
Jan-241865338084773218024.75Late
Feb-24187085808483967018.77On Time
Feb-24187085808483978818.77On Time
Feb-241870858084839812018.97On Time
Feb-24187085808484005025.43Late
Feb-241870868084847248018.42On Time
Feb-24187086808484739020.78On Time
Feb-241870868084847448018.92On Time
Feb-241870868084847548018.93On Time
Feb-241870868084860819821.33On Time
Feb-241870868084860921021.28On Time
Feb-2418708680848610118021.27On Time
Feb-241870868084865818018.95On Time
Feb-241870868084865918020.23On Time
Feb-241870868084866018019On Time
Feb-241870868084866118020.98On Time
Feb-241870868084866218020.1On Time
Feb-241870868084866318021.4On Time
Feb-241870868084866418020.28On Time
Feb-24189882808519963127.8Late
Mar-24192666808540163052.15On Time
Mar-241926668085448010800.53On Time
Mar-241926668085487722.17On Time
Mar-24192666808548811702.13On Time
Mar-24192666808548826152.43On Time
Mar-24192666808548831002.47On Time
Mar-24192666808548841602.48On Time
Mar-24192666808548851402.07On Time
Mar-24192666808548862402.48On Time
Mar-2419266680854887201.12On Time
Mar-24192666808548881062.18On Time
Mar-24192666808548892552.1On Time
Mar-24192666808548907452.13On Time
Mar-241926668085489110.48On Time
Mar-241926668085489212.45On Time
Mar-241927338085563418450.13On Time
Mar-24192733808556369900.08On Time
Mar-24192733808556379750.12On Time
Mar-24192733808558382800.9On Time
Mar-24192733808558392310.08On Time
Mar-24192733808558401521.18On Time
Mar-24192733808558416050.37On Time
Mar-24192733808558482750.82On Time
Mar-24192953808558931210.12On Time
Mar-24192953808561973210.27On Time
Mar-241935808085668919801.55On Time
Mar-241935808085669119801.07On Time
Mar-241935808085669318451.2On Time
Mar-241935808085671910500On Time
Mar-241935808085672110800On Time
Mar-241935808085672210800.5On Time
Mar-241935808085672310800.3On Time
Mar-241935808085672410800.8On Time
Mar-24194646808572542624.12Late
Mar-241946468085795825524.1Late
Mar-24194875808583431071.98Late
Mar-2419753380862389105026.13Late
3 ACCEPTED SOLUTIONS
rpinxt
Solution Sage
Solution Sage

Well still like to know how this works with a measure, but I now was able to merge my 2 sources together.

Having 1 table gave me the opportunity to make calculated columns :

rpinxt_0-1712223788525.png

Of course now I have a big advantage for having real fields on which I can filter!

Now putting Timing (former called 'Flag') in a slicer or in a matrix is super easy :

rpinxt_1-1712223876993.png

So I will keep working with these calculated columns but still interested if it also can work with measures

 

 

View solution in original post

@rpinxt In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

You'll need a disconnected table (no relationship to other tables) that has a column with  values Late and On Time. You can use Enter data to create that.

Assuming that the flag is to be calculated by ShipmentNr and Document Number, you'll need to create another measure to return desired result baased on the value of the column from the disconnected table. Example:

 

VAR Late_OnTime =
    SELECTEDVALUE ( disconnectedtable[columm] )
RETURN
    SWITCH (
        Late_OnTime = "Late",
        SUMX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    SUMMARIZE (
                        'Shipment ATA',
                        'Shipment ATA'[ATA],
                        'Shipment ATA'[D&T],
                        'Shipment ATA'[ShipmentNr],
                        'Shipment ATA'[Document Number]
                    ),
                    "@HourDiff", [HourDiff]
                ),
                "@Flag",
                    VAR __HOURDIFF =
                        DIVIDE ( DATEDIFF ( [ATA], [D&T], MINUTE ), 60 )
                    RETURN
                        IF ( NOT ISBLANK ( [@HourDiff] ) && __HOURDIFF > 24, 1, 0 )
            ),
            [@Flag]
        ), "OnTime",
        SUMX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    SUMMARIZE (
                        'Shipment ATA',
                        'Shipment ATA'[ATA],
                        'Shipment ATA'[D&T],
                        'Shipment ATA'[ShipmentNr],
                        'Shipment ATA'[Document Number]
                    ),
                    "@HourDiff", [HourDiff]
                ),
                "@Flag",
                    VAR __HOURDIFF =
                        DIVIDE ( DATEDIFF ( [ATA], [D&T], MINUTE ), 60 )
                    RETURN
                        IF ( NOT ISBLANK ( [@HourDiff] ) && __HOURDIFF <= 24, 1, 0 )
            ),
            [@Flag]
        )
    )

 

The above formula assumes that you are going to count the late and on time rows at the granularity level of of ShipmentNr and Document Number.
By the way, have you tried using Field Parameters? You'll still need to create a separate measure for Late and On Time.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

7 REPLIES 7
rpinxt
Solution Sage
Solution Sage

Well still like to know how this works with a measure, but I now was able to merge my 2 sources together.

Having 1 table gave me the opportunity to make calculated columns :

rpinxt_0-1712223788525.png

Of course now I have a big advantage for having real fields on which I can filter!

Now putting Timing (former called 'Flag') in a slicer or in a matrix is super easy :

rpinxt_1-1712223876993.png

So I will keep working with these calculated columns but still interested if it also can work with measures

 

 

@rpinxt In general, to use a measure in that way, you need to use the Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler I will study this.

danextian
Super User
Super User

Hi @rpinxt ,

 

How do you calculate Flag?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian this is used for Flag:

Flag =
VAR _HOURDIFF = DIVIDE(DATEDIFF(MAX('Shipment ATA'[ATA]),MAX(SC1[D&T]),MINUTE),60)
RETURN
IF(NOT ISBLANK([HourDiff]),
    IF(_HOURDIFF>24,"Late","On Time")
)

You'll need a disconnected table (no relationship to other tables) that has a column with  values Late and On Time. You can use Enter data to create that.

Assuming that the flag is to be calculated by ShipmentNr and Document Number, you'll need to create another measure to return desired result baased on the value of the column from the disconnected table. Example:

 

VAR Late_OnTime =
    SELECTEDVALUE ( disconnectedtable[columm] )
RETURN
    SWITCH (
        Late_OnTime = "Late",
        SUMX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    SUMMARIZE (
                        'Shipment ATA',
                        'Shipment ATA'[ATA],
                        'Shipment ATA'[D&T],
                        'Shipment ATA'[ShipmentNr],
                        'Shipment ATA'[Document Number]
                    ),
                    "@HourDiff", [HourDiff]
                ),
                "@Flag",
                    VAR __HOURDIFF =
                        DIVIDE ( DATEDIFF ( [ATA], [D&T], MINUTE ), 60 )
                    RETURN
                        IF ( NOT ISBLANK ( [@HourDiff] ) && __HOURDIFF > 24, 1, 0 )
            ),
            [@Flag]
        ), "OnTime",
        SUMX (
            ADDCOLUMNS (
                ADDCOLUMNS (
                    SUMMARIZE (
                        'Shipment ATA',
                        'Shipment ATA'[ATA],
                        'Shipment ATA'[D&T],
                        'Shipment ATA'[ShipmentNr],
                        'Shipment ATA'[Document Number]
                    ),
                    "@HourDiff", [HourDiff]
                ),
                "@Flag",
                    VAR __HOURDIFF =
                        DIVIDE ( DATEDIFF ( [ATA], [D&T], MINUTE ), 60 )
                    RETURN
                        IF ( NOT ISBLANK ( [@HourDiff] ) && __HOURDIFF <= 24, 1, 0 )
            ),
            [@Flag]
        )
    )

 

The above formula assumes that you are going to count the late and on time rows at the granularity level of of ShipmentNr and Document Number.
By the way, have you tried using Field Parameters? You'll still need to create a separate measure for Late and On Time.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Great @danextian !

Much more complicated than using calculated columns 😉

But still good to see this and learn from it.

Thanks!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors