Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Daniel_Gatti
Regular Visitor

Sum values between multiple periods

Hello,

I have the following model in my Power BI report:modelmodel

My first measure is a simple sum:

01 Total Sale = SUM(fSales[Sale])

 

What I'm trying to achieve is a measure that calculates the sum of Sales when the architect is active for a vendor. So I created the measure: 99 Total Sale Active Architect

 

99 Total Sale Active Architect =
VAR Carteira_Arquitetos = VALUES(Carteira[Cod Architect])
VAR Carteira_inicio = min(Carteira[Start date])
VAR Carteira_Fim = max(Carteira[end date])

RETURN

CALCULATE(
     Medidas[01 Total Sale],
     FILTER(
          fSales,
          fSales[Cod Architect] IN Carteira_Arquitetos &&
          (fSales[Data] > Carteira_inicio &&
          fSales[Data] < Carteira_Fim)
          )
)

 

Wich was working fine until a same architect has more than one active period like this:

 

Carteira.png

Now my measure is returning the wrong value:

report.jpg

Thanks in advance

1 ACCEPTED SOLUTION

Hi @Daniel_Gatti 
Here is the sample file with the solution https://we.tl/t-wcDtQlG6IL

1.png

99 Total Sale Active Architect = 
CALCULATE (
    Medidas[01 Total Venda],
    FILTER (
        fSales,
        fSales[Cod Architect] IN
        DISTINCT (
            SELECTCOLUMNS (
                FILTER (
                    Carteira,
                    Carteira[Start date] <= fSales[Data]
                        && Carteira[End date] >= fSales[Data]
                ),
                "@CodArchitect", Carteira[Cod Architect]
            )
        )
    )
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Daniel_Gatti 
Please try

99 Total Sale Active Architect =
VAR CurrentDate =
    MAX ( dCalendar[Date] )
VAR Carteira_Arquitetos =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER (
                Carteira,
                Carteira[Start date] <= CurrentDate
                    && Carteira[End date] <= CurrentDate
            ),
            "@CodArchitect", Carteira[Cod Architect]
        )
    )
RETURN
    CALCULATE (
        Medidas[01 Total Sale],
        fSales[Cod Architect] IN Carteira_Arquitetos
    )

Hello @tamerj1 

 

I didn't worked. The result is still showing 3500, when it should be 1500, because ADRIANA C was not active between 01/02/2022 till 28/02/2022

 

response1.jpg

Here's the link for the file:

https://drive.google.com/file/d/1_HGHM9_f2qkyVGRtQZSVN3WmF_tbakIj/view?usp=sharing

 

Hi @Daniel_Gatti 
Here is the sample file with the solution https://we.tl/t-wcDtQlG6IL

1.png

99 Total Sale Active Architect = 
CALCULATE (
    Medidas[01 Total Venda],
    FILTER (
        fSales,
        fSales[Cod Architect] IN
        DISTINCT (
            SELECTCOLUMNS (
                FILTER (
                    Carteira,
                    Carteira[Start date] <= fSales[Data]
                        && Carteira[End date] >= fSales[Data]
                ),
                "@CodArchitect", Carteira[Cod Architect]
            )
        )
    )
)

@tamerj1 

thank you so much!😀

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.