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
arlequin71
Helper II
Helper II

Category Apportion from 5 Categories to 4 Categories Matrix

Hello,

 

I looking for an efficient / straight forward method to build a 4 Categories Matrix Table using the following rules from an original 5 categories Matrix.

notes:

There are several other columns not included in this example.

Segment and Sales belongs to 2 different tables 

 

- Segment E to be apportioned in new Matrix Segment A by 10 %

- Segment E to be apportioned in new Matrix Segment B by 70 %

- Segment E to be apportioned in New Matrix Segment C by 20 %

2019-07-30_15h33_19.png

Thanks a lot in advance for your help.

 

 

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi,

Did you create a column for your Table by expression?(In my sample, the table SALE is your table segment, and SEGMENT is your Table )

173.PNG

172.PNG

Columnseg = 
CALCULATE (
    [Total Sales],
    FILTER ( SALE, SALE[Segment] <> RELATED ( SEGMENT[name] ) )
)

Then you need to create two measures like below

Measure = 
CALCULATE (
    [Total Sales],
    FILTER ( SEGMENT, SEGMENT[name] = MIN ( SALE[Segment] ) )
)
    + MIN ( SEGMENT[Columnseg] ) * MIN ( SEGMENT[PERCENTAGE] )
all = 
IF (
    HASONEVALUE ( SEGMENT[name] ),
    [Measure],
    SUMX ( ALLSELECTED ( SEGMENT ), [Measure] )
)

Then use [all] in Matrix

 

Best Regards,
Zoe Zhi

View solution in original post

6 REPLIES 6
dax
Community Support
Community Support

Hi arlequin71,

I assume that your sample might be similar to below

146.png

Create a column by expression in segment

Column =
CALCULATE (
    SUM ( SALE[AMOUNT] ),
    FILTER ( SALE, SALE[ID] <> RELATED ( SEGMENT[IDNAME] ) )
)

Then create two measures like below

Measure =
CALCULATE (
    SUM ( SALE[AMOUNT] ),
    FILTER ( SEGMENT, SEGMENT[IDNAME] = MIN ( SALE[ID] ) )
)
    + MIN ( SEGMENT[Column] ) * MIN ( SEGMENT[PERCENTAGE] )
all =
IF (
    HASONEVALUE ( SEGMENT[IDNAME] ),
    [Measure],
    SUMX ( ALLSELECTED ( SEGMENT ), [Measure] )
)

147.png

Best Regards,

Zoe Zhi

 

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

Hello @dax , thanks for your answer.  Apparently i missed some important details... I don't have a Percentage Column at Segment Table and there is a customer hierarchy level which is grouped by Segment category.  The 5 Categories Matrix should be transformed in a 4 Categories Matrix apportioning the original E Segment over A, B, C and D Segment, so in the desired new Matrix :

 

A Segment Sales = A + 0.1 x E Segment Sales

B Segment Sales = B + 0.7 x E Segment Sales

C Segment Sales = C + 0.2 x E Segment Sales

D Segment Sales = D Segment Sales

 

Attached an example.

 

Thanks a lot in advance for your help.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TZNJEsJADAP/MmcO2J6wHNlekcorgP9TkSWbk1VdWdTjZF2HjcN4fN+ffd7GdliHk3iRIIkik2Sfd5CFZKlrTiSYIGeSfb5ALiT7fIJcSa71HDuq4rHus6pt1cBUHIFM1a27m8ojkKl+hmQSsDYwKVg7mCQQyKSBkMzlgcCzlof/nX8toDfg8kBIN5eHt4fLw9vD5YHALvJAyJN3eSDwefLw9gh5IGSXkEf0PkIe8fcl1afU+wh5ZEgmj2iPkEe0R8gjeh8hj+h9hDwQst+UR4Zk8kDIc5nyQCCTB0K+Y9ZPMZvJA4H3ygOBTB4I/MfkgcDO8pi9j0UeCz22Hw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Customer = _t, Segment = _t])
in
    Source

 

dax
Community Support
Community Support

Hi

 

I want to know the sample you provide is sale table, right? Based on your sample, you might will link that table to sale fact table. I didn't create a fact table, I just create a column by range() function, I think the logic is similar(in your scenario, you could create relationship between two tables to calculate total.)

160.PNG

Then create table like below

161.PNG

Then you could follow my first reply to creaet column and measures, it will work

163.PNG

Best Regards,

Zoe Zhi

 

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

Hello @dax 

Sorry i think i'm still missing a step.  I modified my data model according to your instructions but i have an additional table (with Name and Percentage) that doesn't fit match the meassure you published.

 

Thanks again for your help.

 

This is what i have now:


2019-08-01_09h49_49.png

 

 

 

 

 

 

 

 

 

 

 

2019-08-01_09h51_07.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTLQM1SK1YlWcgKzzcFsZzDbCMx2AbGVYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, percentage = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"percentage", type number}})
in
    #"Changed Type"
dax
Community Support
Community Support

Hi,

Did you create a column for your Table by expression?(In my sample, the table SALE is your table segment, and SEGMENT is your Table )

173.PNG

172.PNG

Columnseg = 
CALCULATE (
    [Total Sales],
    FILTER ( SALE, SALE[Segment] <> RELATED ( SEGMENT[name] ) )
)

Then you need to create two measures like below

Measure = 
CALCULATE (
    [Total Sales],
    FILTER ( SEGMENT, SEGMENT[name] = MIN ( SALE[Segment] ) )
)
    + MIN ( SEGMENT[Columnseg] ) * MIN ( SEGMENT[PERCENTAGE] )
all = 
IF (
    HASONEVALUE ( SEGMENT[name] ),
    [Measure],
    SUMX ( ALLSELECTED ( SEGMENT ), [Measure] )
)

Then use [all] in Matrix

 

Best Regards,
Zoe Zhi

Thanks a lot, it works!

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.