cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SimonChung_GGGG
Helper III
Helper III

Frequency Matrix Table

Hi PB Experts,

 

I've tried hard to create a table but fail.

 

The data are simplified as this

image.png

 

I would like to make a matrix table, no. of visit (no. of Sales) will be displayed in column
This is the expected result:

image.png


Here is the PBIX Download .

 

wish that somebody can help, many thanks!

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi  @SimonChung_GGGG 

For your case, just create a measure with logic as below:

Result = 
VAR _table =
    FILTER (
        CROSSJOIN (
            SUMMARIZE (
                'Table',
                'Table'[Royality],
                'Table'[Customer],
                "Totalsales", CALCULATE ( SUM ( 'Table'[Sales] ) ),
                "Frequency", CALCULATE ( COUNTA ( 'Table'[Customer] ) )
            ),
            Visit
        ),
        [Frequency] = [Value]
    )
RETURN
    SUMX ( _table, [Totalsales] )

Result:

3.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi  @SimonChung_GGGG 

For your case, just create a measure with logic as below:

Result = 
VAR _table =
    FILTER (
        CROSSJOIN (
            SUMMARIZE (
                'Table',
                'Table'[Royality],
                'Table'[Customer],
                "Totalsales", CALCULATE ( SUM ( 'Table'[Sales] ) ),
                "Frequency", CALCULATE ( COUNTA ( 'Table'[Customer] ) )
            ),
            Visit
        ),
        [Frequency] = [Value]
    )
RETURN
    SUMX ( _table, [Totalsales] )

Result:

3.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

A million thanks! This question has been struggling me for a few days

BA_Pete
Super User
Super User

Hi @SimonChung_GGGG ,

 

Use this code to transform your data first:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0MACSxkqxOhC+ERrfGInvBFdvBOcbofGNkfjOYPUgAhvXBawbrtgFrBmFa0Is1xXIMgVxTcFcNxjXCM41QeUaQrmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, Sales = _t, Royality = _t]),
    chgSalesType = Table.TransformColumnTypes(Source,{{"Sales", Int64.Type}}),
    #"groupRows&Count" = Table.Group(chgSalesType, {"Customer", "Royality"}, {{"sales", each List.Sum([Sales]), type number}, {"visits", each Table.RowCount(_), Int64.Type}}),
    chgVisitsType = Table.TransformColumnTypes(#"groupRows&Count",{{"visits", type text}})
in
    chgVisitsType

In Power Query, go to New Source > Blank Query then in Advanced Editor paste my code over the default code.

 

Then in the report view, set up your matrix like this:

SimonChung.PNG

Pete

Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through June10th!

Power BI Dev Camp Session 22 without aka link and time 768x460.jpg

Check it Out!

Watch Session 22 Ted's Dev Camp along with past sessions!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!

Top Kudoed Authors