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

Calculated measure with dynamic formula coming from dataset

Hi all,

 

I have to build a measure made with a formula coming from the DB.

Maybe I can solve it in the ETL, but the number of record will increase too much, cause every filter in presentation-time on other dimension/attributes should impact on the calculated formula. So I'm tryng to bring the formula logic into the data-model.

 

e.g. 

DataType | Value

A | 100

A | 200

B | 300

B | 200

C | 300

X | 0,34

Y | 2,77

F1 | A+B-C

F2 | (A + B) * X - (C * Y)

F3 | ((A * X) + (B * Y) - (C * B)) / C

 

No prob when there are only + or - in the formula as in the case of F1 formula: SUMX (Value * Sign)... where sign is "1" or "-1".

In case of F2 and F3 it's more difficult, cause I have bracket and multiplication, and the lenght/structure is not given. Some idea on how can I solve that?

 

Thanks

Fabio

7 REPLIES 7
fabiuzz
Frequent Visitor

Hi Majidbhatti, unluckily no update.

Majidbhatti
Advocate IV
Advocate IV

I have similar ETL requirement. @fabiuzz any update?

saini-harish
Regular Visitor

Hi, have you got solution for this problem? I would like to think that this can be solved using "M"? I've similar problem but don't wish to reinvent the wheel

 

Cheers,

Harish

Hi Harish,

actually I haven't found a way to do this with DAX formula.

 

Maybe in "M" you can do something, but I think you can only reach a part of the solution. My goal was not only to calculate row by row value, but also to apply the formula in the aggregation level that should not be the simple sum (or the average, or the count, or whatever else...). Obviously all affected by the filters I use in the reporting phase.

 

Bye!

Fabio

 

v-shex-msft
Community Support
Community Support

HI @fabiuzz,

 

AFAIK, power bi not suitable for calculate with specific cell value, it not contains column index and row index.
So you had to manually look up specific records and summary them to calculate.

 

Sample measure:

F1 =
VAR A =
    CALCULATE (
        SUM ( table[Value] ),
        FILTER ( ALL ( Table ), Table[Data Type] = "A" )
    )
VAR B =
    CALCULATE (
        SUM ( table[Value] ),
        FILTER ( ALL ( Table ), Table[Data Type] = "B" )
    )
VAR C =
    CALCULATE (
        SUM ( table[Value] ),
        FILTER ( ALL ( Table ), Table[Data Type] = "C" )
    )
VAR X =
    CALCULATE (
        SUM ( table[Value] ),
        FILTER ( ALL ( Table ), Table[Data Type] = "X" )
    )
VAR Y =
    CALCULATE (
        SUM ( table[Value] ),
        FILTER ( ALL ( Table ), Table[Data Type] = "Y" )
    )
RETURN
    A + B
        - C

F2
    =
    VAR A =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "A" )
        )
    VAR B =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "B" )
        )
    VAR C =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "C" )
        )
    VAR X =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "X" )
        )
    VAR Y =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "Y" )
        )
    RETURN
        ( A + B )
            * X
            - ( C * Y )

F3
    =
    VAR A =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "A" )
        )
    VAR B =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "B" )
        )
    VAR C =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "C" )
        )
    VAR X =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "X" )
        )
    VAR Y =
        CALCULATE (
            SUM ( table[Value] ),
            FILTER ( ALL ( Table ), Table[Data Type] = "Y" )
        )
    RETURN
        ( ( A * X )
            + ( B * Y )
            - ( C * B ) )
            / C

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Ok, this work, but the matter is that I want to autogenerate (or autointerpretate) the formula u write manually, starting from the composition of the formula stored in table inside the dataset.

 

In other words the formula F1,F2,F3,... should be evalueted from the dataset: something like convertstringtoformula...

Hi @fabiuzz,

 

 

As I said, power bi not contains column index and row index so you need to manually lookup for specific value.

I think it is impossible to use dax to achieve.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.