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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ekaponkratova
Frequent Visitor

If it is the first date or last date use one aggregation; if any other day, use another aggregation

Let's assume I have the below dataset. 

1.png

What I need to create the below matrix where if it is the beginning or month end, I aggregate A or B in Category 1 but if it is any other day in a month but 1st or last, I am tagging A or B in Category 2 and calculate COUNT. I guess I need to use SWITCH, is not it?

2.png

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@ekaponkratova - 

Maybe this is what you were looking for?

 

I created a Calculated Column, to get labels for Columns as:

Column = 
VAR startMonth = STARTOFMONTH(TableName[date])
VAR endMonth = ENDOFMONTH(TableName[date].[Date])

RETURN 
IF(
    TableName[date]=startMonth || TableName[date]=endMonth,
    "Category 1",
    "Category 2"
)

Then I created a Measure as:

Measure = 
SWITCH (
    TRUE (),
    STARTOFMONTH ( TableName[date] ) = MAX ( TableName[date] )
        || ENDOFMONTH ( TableName[date].[Date] ) = MAX ( TableName[date] ), SUM ( TableName[quantity] ),
    STARTOFMONTH ( TableName[date] ) <> MAX ( TableName[date] )
        || ENDOFMONTH ( TableName[date].[Date] ) <> MAX ( TableName[date] ), COUNTROWS ( TableName )
)

Results in the left matrix:

2.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
ChrisMendoza
Resident Rockstar
Resident Rockstar

@ekaponkratova - 

Maybe this is what you were looking for?

 

I created a Calculated Column, to get labels for Columns as:

Column = 
VAR startMonth = STARTOFMONTH(TableName[date])
VAR endMonth = ENDOFMONTH(TableName[date].[Date])

RETURN 
IF(
    TableName[date]=startMonth || TableName[date]=endMonth,
    "Category 1",
    "Category 2"
)

Then I created a Measure as:

Measure = 
SWITCH (
    TRUE (),
    STARTOFMONTH ( TableName[date] ) = MAX ( TableName[date] )
        || ENDOFMONTH ( TableName[date].[Date] ) = MAX ( TableName[date] ), SUM ( TableName[quantity] ),
    STARTOFMONTH ( TableName[date] ) <> MAX ( TableName[date] )
        || ENDOFMONTH ( TableName[date].[Date] ) <> MAX ( TableName[date] ), COUNTROWS ( TableName )
)

Results in the left matrix:

2.PNG






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



And you are officially genius. Just question. Why do we need the 2nd measure? Cannot I just use quantity?

@ekaponkratova -

 

I thought you needed a SUM([quantity]) when Category 1 othewise COUNTROWS. The Measure is trying to do that.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Hm, I still need to test, but I what I did, I re-used your category and then, just dropped quantity to values and used sum as aggregation. 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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