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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
db_programmer
Frequent Visitor

CONCATENATEX with Only Relevant Values

I have a SUMMARIZECOLUMNS query that produces this table:

 

Block IDYear MonthDay of Week - AbbreviationWeek NumberTotal UsedTotal UnusedTotal AvailableEarly TimeLate Time
72202301Mon21557-32712307301500
72202301Wed21 770-42013507301500
72202301Wed112866413507301500
72202301Mon51488-13813507301500
72202301Mon42044-69413507301500
72202301Wed498037013507301500

 

I would like to summarize this further so that it is only two rows, one for each of the two days of the week in the dataset, e.g., Mon and Wed.  The Weeks column should be a concatenated list of the weeks, e.g., Mon would be  "2,4,5" and Wed would be "1,2,4":

 

Block IDYear MonthDay of Week - AbbreviationWeeksTotal UsedTotal UnusedTotal AvailableEarly TimeLate Time
72202301Mon2,4,512767413507301500
72202301Wed1,2,4103331713507301500

 

 

I've tried replacing the [Week Number] column with a new column [Weeks] using the CONCATENATEX function but it won't even run:

 

 EVALUATE
VAR PLACEMAT_PRELIM =
    SUMMARIZECOLUMNS (
        'Block'[Block ID],
        'Calendar'[Year Month],
        'Calendar'[Day of Week - Abbreviation],
       -- 'Calendar'[Week Number],
        "Weeks",CONCATENATEX(FILTER(Calendar,[Day of Week - Abbreviation]=EARLIER([Day of Week - Abbreviation)),Calendar[Week Number],", " ),
       FILTER (
            'Hourly Block Utilization Util Group Scenario',
            'Hourly Block Utilization Util Group Scenario'[UtilGroupScenario] = "Performed"
        ),
        FILTER ( 'Block', 'Block'[Block ID] = 72 ),
        FILTER ( 'Calendar', 'Calendar'[Year Month] = "202301" ),
        "Week",CONCATENATEX(
        "Total Used", [NetBlockUtilUsedTime],
        "Total Unused", [netblockutilunusedtime],
        "Total Available", [NetBlockUtilAvailableTime],
        "Early Time",
            IGNORE (
                MIN ( 'Hourly Block Utilization Denominator'[OverallSlotStartTimeKey] )
            ),
        "Late Time", IGNORE ( MAX ( 'Hourly Block Utilization Denominator'[OverallSlotEndTimeKey] ) )
    )
    )
   
RETURN PLACEMAT_PRELIM

 

If I write the [Weeks] column like below, it returns ALL the weeks in the month for the given day of the week, not just the ones that are in the intilial SUMARIZECOLUMNS table:

 

  "Weeks",
            IGNORE (
                CONCATENATEX (
                    FILTER (
                        VALUES ( 'Calendar'[Week Number] ),
                        NOT ISBLANK ( MAX ( 'Calendar'[Day of Week - Abbreviation] ) )
                    ),
                    'Calendar'[Week Number],
                    ","
                )
            ),

 

What's a better way to approach this?

 

1 ACCEPTED SOLUTION

Thank you.  I couldn't get yours to work completely - it was still showing all the weeks of the month relevant to that calendar date, but not the weeks relevant to the data in each row.  I figured out another way, inspired by your idea of recalculating the totals, using the GROUPBY table function and then finally the ADDCOLUMNS table function.  I think the key piece is the CONCATENATEX function is not referencing the genric Calendar table but the specific table variable created in step 1.  Thank you for your suggestion.

 

EVALUATE
VAR PLACEMAT_1 =
    SUMMARIZECOLUMNS (
        'Block'[Block ID],
        'Calendar'[Year Month],
        'Calendar'[Day of Week - Abbreviation],
        'Calendar'[Week Number],
        FILTER ( 'Block', 'Block'[Block ID] = 72 ),
        FILTER ( 'Calendar', 'Calendar'[Year Month] = "202301" ),
        "Total Used", [NetBlockUtilUsedTime],
        "Total Unused", [netblockutilunusedtime],
        "Total Available", [NetBlockUtilAvailableTime],
        "Early Time",
            IGNORE (
                MIN ( 'Hourly Block Utilization Denominator'[OverallSlotStartTimeKey] )
            ),
        "Late Time", IGNORE ( MAX ( 'Hourly Block Utilization Denominator'[OverallSlotEndTimeKey] ) )
    )
VAR PLACEMAT_2 =
    GROUPBY (
        PLACEMAT_1,
        [Block ID],
        [Year Month],
        [Day of Week - Abbreviation],
        "Total Used", SUMX ( CURRENTGROUP (), [Total Used] ),
        "Total Unused", SUMX ( CURRENTGROUP (), [Total Unused] ),
        "Total Available", SUMX ( CURRENTGROUP (), [Total Available] ),
        "Early Time", MINX ( CURRENTGROUP (), [Early Time] ),
        "Late Time", MAXX ( CURRENTGROUP (), [Late Time] )
    )
RETURN
    ADDCOLUMNS (
        PLACEMAT_2,
        "Weeks",
            CONCATENATEX (
                FILTER (
                    PLACEMAT_1,
                    [Day of Week - Abbreviation] = EARLIER ( [Day of Week - Abbreviation] )
                ),
                [Week Number],
                ",",
                [Week Number]
            )
    )

 

View solution in original post

2 REPLIES 2
Dangar332
Super User
Super User

hi, @db_programmer 

try below cofe for new table

just adjust your column and table name

SUMMARIZE(
	'Table',
	'Table'[Block ID],
	'Table'[Year Month],
	'Table'[Day of Week - Abbreviation],
	'Table'[Early Time],
	'Table'[Late Time],
	"Total used",sum('Table'[Total Used]),
	"total unused",SUM('Table'[Total Unused]),
	"total avilable",SUM('Table'[Total Available]),
	"Weeks",
	  var a= VALUES('Table'[Week Number])
	  RETURN
	   CONCATENATEX(a,'Table'[Week Number],", "))
	

 

Dangar332_0-1711086629429.png

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

 

 

Thank you.  I couldn't get yours to work completely - it was still showing all the weeks of the month relevant to that calendar date, but not the weeks relevant to the data in each row.  I figured out another way, inspired by your idea of recalculating the totals, using the GROUPBY table function and then finally the ADDCOLUMNS table function.  I think the key piece is the CONCATENATEX function is not referencing the genric Calendar table but the specific table variable created in step 1.  Thank you for your suggestion.

 

EVALUATE
VAR PLACEMAT_1 =
    SUMMARIZECOLUMNS (
        'Block'[Block ID],
        'Calendar'[Year Month],
        'Calendar'[Day of Week - Abbreviation],
        'Calendar'[Week Number],
        FILTER ( 'Block', 'Block'[Block ID] = 72 ),
        FILTER ( 'Calendar', 'Calendar'[Year Month] = "202301" ),
        "Total Used", [NetBlockUtilUsedTime],
        "Total Unused", [netblockutilunusedtime],
        "Total Available", [NetBlockUtilAvailableTime],
        "Early Time",
            IGNORE (
                MIN ( 'Hourly Block Utilization Denominator'[OverallSlotStartTimeKey] )
            ),
        "Late Time", IGNORE ( MAX ( 'Hourly Block Utilization Denominator'[OverallSlotEndTimeKey] ) )
    )
VAR PLACEMAT_2 =
    GROUPBY (
        PLACEMAT_1,
        [Block ID],
        [Year Month],
        [Day of Week - Abbreviation],
        "Total Used", SUMX ( CURRENTGROUP (), [Total Used] ),
        "Total Unused", SUMX ( CURRENTGROUP (), [Total Unused] ),
        "Total Available", SUMX ( CURRENTGROUP (), [Total Available] ),
        "Early Time", MINX ( CURRENTGROUP (), [Early Time] ),
        "Late Time", MAXX ( CURRENTGROUP (), [Late Time] )
    )
RETURN
    ADDCOLUMNS (
        PLACEMAT_2,
        "Weeks",
            CONCATENATEX (
                FILTER (
                    PLACEMAT_1,
                    [Day of Week - Abbreviation] = EARLIER ( [Day of Week - Abbreviation] )
                ),
                [Week Number],
                ",",
                [Week Number]
            )
    )

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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