Forum Discussion
Calculations based on other 2 datasets
You can refer to the following sample.
1.First, you need to unpivot your tables to the following.
You can refer to the following queries.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIyoBIRqxOt5ERtA52pbaALtQ10pbaBblQ1MBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, OctCFY = _t, NovCfy = _t, DecCFY = _t, JanNfy = _t, Febnfy = _t, Marnfy = _t, Aprnfy = _t, maynfy = _t, junnfy = _t, Julnfy = _t, Augnfy = _t, Sepnfy = _t, Octnfy = _t, Novnfy = _t, Decnfy = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"OctCFY", Int64.Type}, {"NovCfy", Int64.Type}, {"DecCFY", Int64.Type}, {"JanNfy", Int64.Type}, {"Febnfy", Int64.Type}, {"Marnfy", Int64.Type}, {"Aprnfy", Int64.Type}, {"maynfy", Int64.Type}, {"junnfy", Int64.Type}, {"Julnfy", Int64.Type}, {"Augnfy", Int64.Type}, {"Sepnfy", Int64.Type}, {"Octnfy", Int64.Type}, {"Novnfy", Int64.Type}, {"Decnfy", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company"}, "Attribute", "Value"),
#"Uppercased Text" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Attribute", Text.Proper, type text}})
in
#"Uppercased Text"let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0oBIRqxOt5ERtA52pbaALtQ10pbaBblQ1MBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Company = _t, OctCFY = _t, NovCfy = _t, DecCFY = _t, JanNfy = _t, Febnfy = _t, Marnfy = _t, Aprnfy = _t, maynfy = _t, junnfy = _t, Julnfy = _t, Augnfy = _t, Sepnfy = _t, Octnfy = _t, Novnfy = _t, Decnfy = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Company", type text}, {"OctCFY", Int64.Type}, {"NovCfy", Int64.Type}, {"DecCFY", Int64.Type}, {"JanNfy", Int64.Type}, {"Febnfy", Int64.Type}, {"Marnfy", Int64.Type}, {"Aprnfy", Int64.Type}, {"maynfy", Int64.Type}, {"junnfy", Int64.Type}, {"Julnfy", Int64.Type}, {"Augnfy", Int64.Type}, {"Sepnfy", Int64.Type}, {"Octnfy", Int64.Type}, {"Novnfy", Int64.Type}, {"Decnfy", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Company"}, "Attribute", "Value"),
#"Uppercased Text" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Attribute", Text.Proper, type text}})
in
#"Uppercased Text"
2.Then create the following tables.
Type table
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Rc4xCoAwEETRu6T2EoJYBNTCMqSIYbUJYwhGyO0FYTPdY1iW75yxAfFsxg/OzHIol1CUYy5cm9JWkKnf1ku5S1Zu8VGu96ucJPYPAWAD2AA2cG1gA5nABrABbAAbwIaf/gM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
in
#"Added Index"
Company table.
Company = SUMMARIZE('Admin Cost',[Company])
3.Create the following relationships among the tables.
4.Create the following measure.
MEASURE =
VAR a =
GENERATESERIES ( 2, 23, 3 )
VAR b =
SELECTEDVALUE ( 'Type'[Index] ) - 4
VAR c =
SELECTEDVALUE ( 'Type'[Index] ) - 2
VAR d =
CALCULATE (
SUM ( 'Total Income'[Value] ),
ALLSELECTED ( 'Type' ),
'Type'[Index] <= c,
'Type'[Index] >= b
)
VAR e =
CALCULATE (
SUM ( 'Admin Cost'[Value] ),
ALLSELECTED ( 'Type' ),
'Type'[Index] <= c,
'Type'[Index] >= b
)
RETURN
IF ( SELECTEDVALUE ( 'Type'[Index] ) IN a, d * 0.25 + e * 0.25, 0 )
5.Put the following fields to a matrix visual.
Output
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- GokilaRaviraj1 year agoHelper II
Hi Anonymous
Thanks for your reply. I tried this measure.
I am wondering why the values are not coming for Febcfy,Maycfy,Augcfy,Novcfy even though you have given this code.
GENERATESERIES ( 2, 23, 3 )I also have a question on type table month data, Now this has months from Jan cfy to dec nfy. But I want to show these months from jancfy to decnfy only when current month is Jan.when Current month is Feb, It has to show months from Febcfy to decnfy and this calculations is not needed. It has to just carry out the calculated vlaues previous month. Calculation has to be done again , when current month becomes Jan the next yearIs this can be done in DAX ?- Anonymous1 year agoNot applicable
Thanks for your quick reply, for the first question, because the data you provided is start from October, so it will return 0 for Febcfy,Maycfy,Augcfy,Novcfy
For the second question, what is the logic of the calculated vlaues previous month,and do you use the today() to define the current month?
Best Regards!
Yolo Zhu
- Anonymous1 year agoNot applicable
Thanks for your quicl reply, for the first question, because the data you provided is start from October, so it will return 0 for Febcfy,Maycfy,Augcfy,Novcfy
For the second question, I don't really know the results you want
Best Regards!
Yolo Zhu
- GokilaRaviraj1 year agoHelper II
Hi Anonymous
Now I changed my 2 input tables with months from JanCFY to DecNFY.
In the output table, Value is not showing up for FebCFY column alone. All other columns have values as per the measure.
Do you have any idea on this ?