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

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

Reply
Anonymous
Not applicable

Grouping on two columns according to values sign

Hello,

 

I was wondering if it is possible to do this kind of grouping for two columns based on the sign of the interval values (and how).

The months are selected by a slicer in the report.

 

Thanks for the help

 

GuyInaBall_0-1664789410530.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to the attached sample file with the solution.

3.png2.png1.png

 

Rank = 
VAR Ranking1 =
    RANKX ( FILTER ( 'Table', 'Table'[Value] > 0 ), 'Table'[Month],, ASC, Dense )
VAR Ranking2 =
    RANKX ( FILTER ( 'Table', 'Table'[Value] < 0 ), 'Table'[Month],, ASC, Dense )
VAR Result =
   IF ( 'Table'[Value] > 0, Ranking2, Ranking1 )
RETURN
    Result
Group = 
VAR CurrentGroupTable = 
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Rank] ) )
VAR Starting = 
    MINX ( CurrentGroupTable, 'Table'[Month] )
VAR Ending = 
    MAXX ( CurrentGroupTable, 'Table'[Month] )
RETURN
    FORMAT ( Starting, "MMMM" ) & " - " & FORMAT ( Ending, "MMMM" )
Average Value = AVERAGE ( 'Table'[Value] )

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello @tamerj1 & @Jihwan_Kim , thank you for your nice answsers.

@tamerj1's solution is the closest to what I need. I'll just add a new measure so that the period label reflects more precisely the selected period and hid the month group.

Thank you again for the help and the effort, much appreciated

tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to the attached sample file with the solution.

3.png2.png1.png

 

Rank = 
VAR Ranking1 =
    RANKX ( FILTER ( 'Table', 'Table'[Value] > 0 ), 'Table'[Month],, ASC, Dense )
VAR Ranking2 =
    RANKX ( FILTER ( 'Table', 'Table'[Value] < 0 ), 'Table'[Month],, ASC, Dense )
VAR Result =
   IF ( 'Table'[Value] > 0, Ranking2, Ranking1 )
RETURN
    Result
Group = 
VAR CurrentGroupTable = 
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[Rank] ) )
VAR Starting = 
    MINX ( CurrentGroupTable, 'Table'[Month] )
VAR Ending = 
    MAXX ( CurrentGroupTable, 'Table'[Month] )
RETURN
    FORMAT ( Starting, "MMMM" ) & " - " & FORMAT ( Ending, "MMMM" )
Average Value = AVERAGE ( 'Table'[Value] )

 

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1664797027764.png

 

 

New Table = 
VAR _previousvalue =
    ADDCOLUMNS (
        Data,
        "@prev",
            CALCULATE (
                SUM ( Data[Value] ),
                FILTER ( Data, Data[Month number] = EARLIER ( Data[Month number] ) - 1 )
            )
    )
VAR _condition =
    ADDCOLUMNS (
        _previousvalue,
        "@condition",
            IF ( Data[Value] * [@prev] >= 0, 0, 1 )
    )
VAR _group =
    ADDCOLUMNS (
        _condition,
        "@group",
            SUMX (
                FILTER ( _condition, Data[Month number] <= EARLIER ( Data[Month number] ) ),
                [@condition]
            )
    )
VAR _newtable =
    ADDCOLUMNS (
        _group,
        "@month",
            MAXX (
                FILTER (
                    Data,
                    Data[Month number]
                        = MINX ( FILTER ( _group, [@group] = EARLIER ( [@group] ) ), Data[Month number] )
                ),
                Data[Month]
            ) & "~"
                & MAXX (
                    FILTER (
                        Data,
                        Data[Month number]
                            = MAXX ( FILTER ( _group, [@group] = EARLIER ( [@group] ) ), Data[Month number] )
                    ),
                    Data[Month]
                )
    )
VAR _avgcolumn =
    ADDCOLUMNS (
        _newtable,
        "@avgvalue", AVERAGEX ( FILTER ( _group, [@group] = EARLIER ( [@group] ) ), Data[Value] )
    )
RETURN
    SUMMARIZE ( _avgcolumn, [@month], [@avgvalue] )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.