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
leonardorm
Regular Visitor

How to return the value of a other higher-valued column?

I have 3 tables: iteracao; trabalho; trabalhofoto (log: snapshot (daily)).

 

I need the sum of the "esforço" values of the largest data in the "trabalhofoto" table of data in the "trabalho" table where the data must be less than or equal to the final data ("datefim") of the work. "iteracao".

 

Using the sql below I get the result I need (last image), but how do I do this using DAX?

 

SELECT *,
    (SELECT SUM((SELECT tf.esforco
        FROM trabalhofoto tf
        WHERE t.trabalhoId = tf.trabalhoId AND
             tf.data <= i.dataFim
        ORDER BY tf.data DESC
        LIMIT 1)) as esforcoTotal
    FROM trabalho t) esforcoTotal
FROM iteracao i

iteracao.csv  ( http://dontpad.com/leonardorm/powerbi/iteracao )

IteracaoIteracao

 

trabalho.csv (http://dontpad.com/leonardorm/powerbi/trabalho)

TrabalhoTrabalho

 

trabalhofoto.csv (http://dontpad.com/leonardorm/powerbi/trabalhofoto)

TrabalhoFoto (daily snapshot)TrabalhoFoto (daily snapshot)

 

Expected resultExpected result

1 ACCEPTED SOLUTION
TeigeGao
Solution Sage
Solution Sage

Hi leonardorm,

According to your description, my understanding is that you want to calculate the sum of esforco whose data is max in each trabahoId group and less than the dataFim.

In this scenario, we can use the following DAX query:

Measure =
SUMX (
    SUMMARIZE ( trabalhofoto, trabalho[trabalhoId] ),
    CALCULATE (
        MAXX (
            TOPN (
                1,
                FILTER ( trabalhofoto, trabalhofoto[data] <= MIN ( iteracao[dataFim] ) ),
                trabalhofoto[data], DESC
            ),
            trabalhofoto[esforco]
        )
    )
)

The result will like below:

2132.png

Best Regards,

Teige

View solution in original post

1 REPLY 1
TeigeGao
Solution Sage
Solution Sage

Hi leonardorm,

According to your description, my understanding is that you want to calculate the sum of esforco whose data is max in each trabahoId group and less than the dataFim.

In this scenario, we can use the following DAX query:

Measure =
SUMX (
    SUMMARIZE ( trabalhofoto, trabalho[trabalhoId] ),
    CALCULATE (
        MAXX (
            TOPN (
                1,
                FILTER ( trabalhofoto, trabalhofoto[data] <= MIN ( iteracao[dataFim] ) ),
                trabalhofoto[data], DESC
            ),
            trabalhofoto[esforco]
        )
    )
)

The result will like below:

2132.png

Best Regards,

Teige

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.

Top Solution Authors