Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

sumx, filter, related

Hello,

 

I have 3 table and need to write formula which can calculate sumx per row - 

I want to easure fdduration in tblshiftstandsill and choose filter for "glowna kategoria postoju" equal 4.(columns have value (1-5)

 

Please help me write formula

i trying with related function, relatedtable.. 

for example:

Measure = CALCULATE(SUMX(TBLSHIFTSTANDSTILL, TBLSHIFTSTANDSTILL[FDDURATION]), FILTER(RELATEDTABLE(TBLSTANDSTILLDEF), TBLSTANDSTILLDEF[Główna kategoria postoju]=4))
and its not working 😞 
 
i know i use sum not sumx but its because i dont know to change this to sumx.. 
 

2 Replies

  • some_bih's avatar
    some_bih
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous unexpected values could be based in your case of relatinship flow. Two red boxes shows that table *DEF and *GROUP (upper right table) according to best practice, should have differente many to one/one to many relationship. It could be what your formula is correctly working but this part, relationship is model is not as expected. Check this part.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Please update the formula of your measure [Measure] as below and check if it can return the correct result...

    Measure =
    VAR _list =
        CALCULATETABLE (
            VALUES ( TBLSTANDSTILLDEF[FDSTANDSTILLDEFID] ),
            FILTER ( TBLSTANDSTILLDEF, TBLSTANDSTILLDEF[Główna kategoria postoju] = 4 )
        )
    RETURN
        CALCULATE (
            SUM ( TBLSHIFTSTANDSTILL[FDDURATION] ),
            FILTER ( TBLSHIFTSTANDSTILL, TBLSHIFTSTANDSTILL[FDSTANDSTILLDEFID] IN _list )
        )

    If the above one can't help you, please provide some raw data in your table  'TBLSHIFTSTANDSTILL' and 'TBLSTANDSTILLDEF' (exclude sensitive data) with Text format and your expected result with backend logic and special examples. By the way, which field is the base field when create relationship between these two tables?  It would be helpful to find out the solution. You can refer the following links to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards