Forum Discussion

volfied's avatar
volfied
Frequent Visitor
5 years ago
Solved

Integrating DAX result sets into Data Model

I apologize if this is a duplicate post, but I'm pretty sure my first attempt got lost in the ether. Also, this ultimately is a DAX/Excel question, not a DAX/PowerBI question. I hope that's not a pro...
  • volfied's avatar
    volfied
    5 years ago

    I finally solved this. It was dirt simple. I'm embarrassed I didn't come up with it sooner. I just had to alter my SQL query to return a difference between the current and previous row and sum all that up in DAX. My measure wound up just being:

    Revenue:=VAR MaxDate =
                MAX ( qryPipelineUS[day_last_mod] )
            RETURN
                CALCULATE (
                    SUM ( qryPipelineUS[eveAmtDiff] ),
                    qryPipelineUS[day_last_mod] <= MaxDate
                )

     

    The T-SQL's a little more out of the ordinary, as you have to do partitioning and ROW windows, but it's simple enough once you get used to it. 

    MAX(eh.amount) OVER (
    PARTITION BY ph.pipeline_id, eh.pipeline_event_id
    ORDER BY ph.pipeline_id, eh.pipeline_event_id, eh.date_rec_copy
    ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING
    )