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
jacinto
Frequent Visitor

Valid measure for two fact tables

Hi all,

 

I have two fact tables that couldn't be merged.  The following is dummy data and sample content. The Main table contain most of the data, however, I have also small table with extra information (202120) that I have to take into account to calculate total Emissision.  For 2022, it is easy, for each item just multiply volume by Average factor= totalvolume*average factor=3*(+.5+0.9)/2=2.1

 

For 2021 and 2020 and only fo wheat and soy we have origin, therefore instead of average factor we have to take specifc factor. Example for wheat, 4*0.5+1*0.9=2.9, basically CA and EC factor instead of average. 

The question is, is it possible to have a single measure based on the logic mentioned above? I would greatily appreciate if you guide me how I can achieve this. Thanks in advance!

 

 

jacinto_0-1678278751201.png

jacinto_1-1678278773196.png

 

1 ACCEPTED SOLUTION

dim_item

dim_item = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[item]),
        GROUPBY(factor,factor[item]),
        GROUPBY(main,main[item])
    )
)

bolfri_0-1678382192603.png

 

dim_origin

dim_origin = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[origin]),
        GROUPBY(factor,factor[origin])
    )
)

bolfri_1-1678382246334.png

 

dim_year

dim_year = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[year]),
        GROUPBY(main,main[year])
    )
)

bolfri_2-1678382311946.png

Relationship

bolfri_3-1678382446402.png

 

Volume Sold = SUM('202120'[volume ])
Emmision =
SUMX(
    SUMMARIZE(
        factor,
        dim_item[item],
        factor[factor],
        dim_origin[origin],
        "VolumeForFactor",[Volume Sold]
    ),
    [VolumeForFactor]*factor[factor]
)
 
Result:
bolfri_4-1678383732126.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
bolfri
Super User
Super User

Yes, you can do that by adding dim_origin table that connects 202120 table with factor table, like you did with intermediate. Then it will understand which row corresponds to witch origin. 🙂

 

You can also share the excel with this sample data that you showed here, so I can show you the relationship and measures. 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




It seems I don't have the priviledge to attach the excel but here is the copy paste. 

Main table

 

itemvolume valueyear

othor columns

wheat3562022x
barley2662022x
soy6342022 
vitamin1992022 
amino11232022 
wheat4112021 
barley3442021 
soy1672021 
vitamin4422021 
amino132021 
wheat9112020 
barley4342020 
soy2882020 
vitamin922020 
amino104442020 

202120 table

 

itemvolume yearorigin
wheat42021CA
wheat12021EC
soy42020BR
soy22020CN

 

Factor table 

itemfactororigin
wheat0.5CA
barley0.3BR
soy0.8CN
vitamin1ET
amino3AR
wheat0.9EC
barley0.1GLO
soy2BR
vitamin2ET
amino7US

dim_item

dim_item = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[item]),
        GROUPBY(factor,factor[item]),
        GROUPBY(main,main[item])
    )
)

bolfri_0-1678382192603.png

 

dim_origin

dim_origin = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[origin]),
        GROUPBY(factor,factor[origin])
    )
)

bolfri_1-1678382246334.png

 

dim_year

dim_year = 
DISTINCT(
    UNION(
        GROUPBY('202120','202120'[year]),
        GROUPBY(main,main[year])
    )
)

bolfri_2-1678382311946.png

Relationship

bolfri_3-1678382446402.png

 

Volume Sold = SUM('202120'[volume ])
Emmision =
SUMX(
    SUMMARIZE(
        factor,
        dim_item[item],
        factor[factor],
        dim_origin[origin],
        "VolumeForFactor",[Volume Sold]
    ),
    [VolumeForFactor]*factor[factor]
)
 
Result:
bolfri_4-1678383732126.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much, it was immensly helpful! Ultimately I am trying to come up with one measure that works in different context. I calculated EmissionM for main table like below and then another formula to combine Emission from 202120 table and maint able(Total Emission) 

EmisionM =
SUMX(
    SUMMARIZE(
        factor,
        dim_item[item],
       "avf",AVERAGE( factor[factor]),
       
        "VolumeForFactorM",[Volume SoldM]
    ),
    [VolumeForFactorM]*[avf])
 
Emission Total = var selectedyr = IF(SELECTEDVALUE(dim_year[year])==2020 || SELECTEDVALUE(dim_year[year])==2021, TRUE(),FALSE())
        var selectedcrop = IF(SELECTEDVALUE(dim_item[item])=="soy" || SELECTEDVALUE(dim_item[item])=="wheat",TRUE(),FALSE())
        var tot=IF(selectedyr && selectedcrop,[Emmision],[EmmisionM])
        return tot
It works even though the total is not correct and I believe there must be better way of making it work under any context. 
jacinto_0-1678697942425.png

 

Any suggestions?

amitchandak
Super User
Super User

@jacinto , if these measure are coming from two fact use common dimension to sum up

 

like

 

Sumx(Item , calculate( [totalvolume]*[average factor]) )

 

where totalvolume and average factor are measure from two facts

 

 

But factor is only on the DM table not on the facts table. Aslo volume exisits in both Main table and 202120 table for 2021 and 2021 (basically 202120 table is subset of Main table with origin value known, therefore volume should be multiplied with factor based on the origin). I hope I managed to explain.

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.