Forum Discussion

maricci's avatar
maricci
Regular Visitor
2 years ago
Solved

Subtracting values, threading through several tables

Good day everyone,

I am attaching the PowerBi file.https://drive.google.com/file/d/1HWX0sZt1FZ_JnZCnSu9OTAwhhhum8azq/view?usp=sharing 
I don't know how to subtract the values, which in some cases are positive and in others negative. The principle is as follows, from table lib it is calculated for table t1, column 1 line_1+line_3, then it goes to table met. In table met, it is looked at for each month separately, line_1 covers ran 1,2, and line_3 covers ran 1,2,4. Then we go to the fact table and read the values, which are finally added or subtracted. In the fact table, for the month of January, ran 1 = 5, ran 2 = 8....In the end, the calculation looks like this: 5+8+5+8+5 = 31. And so for every month. Here is another example when we also have subtraction. We also go to table lib first, there we read for table t1, column 2 = line_1 - line_3. Now it is minus because the sign is -1, then we go to table met and read what line_1 and line_3 include, that is, which ran. We arrive at the formula 1+2-1-2-4. We go to the fact table to read these values ​​and we get that the result is 5+8-5-8-5 = -5 for the month of January.

Here is a display and table of how the results should look.

 JanuaryFebruaryMarchTotal
t126301268
131351783
2-5-5-5-15
t2-37-43-20-100
1-19-23-9-51
2-18-20-11-49


Thanks in advance.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi maricci 

    Based on your description, I create the following measure.

    Measure = sumx(VALUES('met'[line]),SUM('fact'[amount]))
    Measure 2 = IF(ISINSCOPE(met[ran]),[Measure],IF(ISINSCOPE(lib[line]),MAX(lib[sign])*[Measure]))
    Measure 3 = SUMX(VALUES(lib[line]),[Measure 2])
    Measure 4 = SUMX(VALUES(lib[column]),[Measure 3])
    Measure 5 = SUMX(VALUES(lib[table]),[Measure 4])

    Then put the meaure 5 to the value.

    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.

     

     

     

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi maricci 

    Based on your description, I create the following measure.

    Measure = sumx(VALUES('met'[line]),SUM('fact'[amount]))
    Measure 2 = IF(ISINSCOPE(met[ran]),[Measure],IF(ISINSCOPE(lib[line]),MAX(lib[sign])*[Measure]))
    Measure 3 = SUMX(VALUES(lib[line]),[Measure 2])
    Measure 4 = SUMX(VALUES(lib[column]),[Measure 3])
    Measure 5 = SUMX(VALUES(lib[table]),[Measure 4])

    Then put the meaure 5 to the value.

    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.