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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filtering Table Values

sha009_0-1641377779049.png

Hello All, @parry2k @smpa01 @AlexisOlson 

I wish to create a Result Table from the Data Table as seen in the attached screenshot. The Result Table must be such that it will show only those values in the three columns which are corresponding to the Maximum of Sum of Order Value.

 

It will be helpful if we can achieve this functionality.

 

Thanks

1 ACCEPTED SOLUTION

@Anonymous  this will be table expression

Table 2 = 
var _grp = GROUPBY('Table','Table'[GUID],'Table'[LPGU],"subTotal by GUIDLPGU",SUMX(CURRENTGROUP(),'Table'[Order Value]))
--var _filt = TOPN(1, FILTER(_grp,var _guid = [GUID] return [GUID]=_guid),[x],DESC)
var _rank = SUMMARIZE(FILTER(ADDCOLUMNS(_grp, "rank", RANKX(FILTER(_grp,[GUID]=EARLIER([GUID])),[subTotal by GUIDLPGU],,DESC)),[rank]=1),[GUID],[LPGU],[subTotal by GUIDLPGU])
return _rank

 

@AlexisOlson  in a table expression is it possible to ask TOPN to return TOPN(1) based on a partiton like in RANKX

 

RANKX(FILTER(_grp,[GUID]=EARLIER([GUID])

 

I tried but failed.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

12 REPLIES 12
AlexisOlson
Super User
Super User

Assuming you have a measure for the sum of Order Value

 

SumOrderValue = SUM ( Table1[Order Value] )

 

then we can write a measure for the top LPGU order fairly neatly:

 

Top LPGU Order =
VAR TopLPGU =
    MAXX ( TOPN ( 1, ALLSELECTED ( Table1[LPGU] ), [SumOrderValue] ), Table1[LPGU] )
RETURN
    CALCULATE ( [SumOrderValue], KEEPFILTERS ( Table1[LPGU] = TopLPGU ) )

 

 

Edit: You can easily make this into a calculated table as follows:

 

SUMMARIZECOLUMNS ( Table1[GUID], Table1[LPGU], "Order Value", [Top LPGU Order] )

 

smpa01
Super User
Super User

@Anonymous  you can write a measure like this

_Measure = 
CALCULATE (
    CALCULATE (
        SUM ( 'Table'[Order Value] ),
        ALLEXCEPT ( 'Table', 'Table'[GUID], 'Table'[LPGU] )
    ),
    KEEPFILTERS (
        TOPN (
            1,
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[GUID] = MAX ( 'Table'[GUID] ) ),
            CALCULATE (
                SUM ( 'Table'[Order Value] ),
                ALLEXCEPT ( 'Table', 'Table'[GUID], 'Table'[LPGU] )
            ), DESC
        )
    )
)

 

smpa01_0-1641394230506.png

 

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01 This looks good. Can we implement this as Calculated Table with all 3 columns?

@Anonymous  this will be table expression

Table 2 = 
var _grp = GROUPBY('Table','Table'[GUID],'Table'[LPGU],"subTotal by GUIDLPGU",SUMX(CURRENTGROUP(),'Table'[Order Value]))
--var _filt = TOPN(1, FILTER(_grp,var _guid = [GUID] return [GUID]=_guid),[x],DESC)
var _rank = SUMMARIZE(FILTER(ADDCOLUMNS(_grp, "rank", RANKX(FILTER(_grp,[GUID]=EARLIER([GUID])),[subTotal by GUIDLPGU],,DESC)),[rank]=1),[GUID],[LPGU],[subTotal by GUIDLPGU])
return _rank

 

@AlexisOlson  in a table expression is it possible to ask TOPN to return TOPN(1) based on a partiton like in RANKX

 

RANKX(FILTER(_grp,[GUID]=EARLIER([GUID])

 

I tried but failed.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I'm not quite sure what you mean but you can simplify your _rank variable to be:

 

 

FILTER (
    _grp,
    RANKX (
        FILTER ( _grp, [GUID] = EARLIER ( Table1[GUID] ) ),
        [subTotal by GUIDLPGU]
    ) = 1
)

 

or like this

 

TOPN (
    1,
    _grp,
    RANKX (
        FILTER ( _grp, [GUID] = EARLIER ( Table1[GUID] ) ),
        [subTotal by GUIDLPGU]
    ), ASC
)

 

@AlexisOlson Thanks.  I was not asking you about RANKX. I was wondering if it is possible to pass on a partitoned table in TOPN like I did in RANKX?

 

Can I pass on a similar table like following in TOPN, so that TOPN (1) gives me thre result for that partiton?

RANKX (
        FILTER ( _grp, [GUID] = EARLIER ( Table1[GUID] ) )

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Sorry, I'm still not sure I understand what you mean by "pass a partitioned table".

 

If you try to write this

TOPN ( 1, FILTER ( _grp, [GUID] = EARLIER ( Table1[GUID] ) ), [...] )

 it just doesn't make any sense because there's no earlier row context to refer to.

amitchandak
Super User
Super User

@Anonymous , Based on what I got, a measure to be used with GUID, LPGU in visual

 

sumx(summarize(Table, Table[GUID], Table[LPGU], "_sum", sum(Table[Order Value] ) ), [_sum]) 

Anonymous
Not applicable

@amitchandak 

Seems that doesn't work as it still fetches multiple values of LPGU, instead it must fetch single values of GUID, LPGU corresponding to Max Sum of Order Value as shown in the Result Table. Also I need to create Result Table as Data Table(not visual table).

@Anonymous , Try like

sumx(summarize(Table, Table[GUID], "_sum", sum(Table[Order Value] ) ), [_sum])

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Anonymous
Not applicable

@amitchandak This too doesn't work and I still can see multiple values of LPGU, GUID and Order Value. 

It needs to go like Result Table Must show filtered GUID, LPGU and Maximum of Sum of Order Value and that Sum of Order Value must be done by LPGU.

 

Unfortunately, I can't present the sample data. You Can take data from the screenshot that I attached. Also keeping the data table here.

 

GUIDLPGUOrder Value
G21KRTG4
G21KRVC3
G21KRTG6
G21KRVC3
G21KRPP5
G65KPIC1
G65KPIC4
G65KKRD6
G65GHCI7
G65GHCI5
G76TTCG5
G76TTRS1
G76TTDS8
G76TTCG5
Anonymous
Not applicable

@amitchandak I'll check now and get back soon. Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors