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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply

sum of values based on date ranges on repetetion of multipe time frames

Hi all,

I am Working for  a requirement in powerbi same schema mentioned in excel format  named in sheet 1. In sheet 1 we need calculation of summing up for date range not individually.In sheet 2 i had input data required for calculation.

please help me out in calculating for multi recurrent time frames.

 

 

Screenshot (42).pngScreenshot (43).png

1 ACCEPTED SOLUTION

Hi, @nagasaikumarb22 

 

I have readjusted the data, please check it again.

Column:

Product Sold = 
IF (
    [State] = "TX",
    CALCULATE (
        SUM ( Requirement[Products Sold] ),
        FILTER (
            'Data input',
            [State] = EARLIER ( 'Data input'[State] )
                && [Date] >= "2021/1/1"
                && [Date] <= "2021/3/31"
        )
    ),
    IF (
        [State] = "FL",
        CALCULATE (
            SUM ( Requirement[Products Sold] ),
            FILTER (
                'Data input',
                [State] = EARLIER ( 'Data input'[State] )
                    && [Date] >= "2021/1/1"
                    && [Date] <= "2022/3/31"
            )
        ),
        IF (
            [State] = "CA",
            CALCULATE (
                SUM ( Requirement[Products Sold] ),
                FILTER (
                    'Data input',
                    [State] = EARLIER ( 'Data input'[State] )
                        && [Date] >= "2021/1/1"
                        && [Date] <= "2023/3/31"
                )
            )
        )
    )
)

vzhangti_0-1649065798606.png

Is this the result you want?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-zhangti
Community Support
Community Support

Hi, @nagasaikumarb22 

 

You can try the following methods.

Column:

Product Sold = 
CALCULATE (
    SUM ( Requirement[Products Sold] ),
    FILTER ( 'Data input', [State] = EARLIER ( 'Data input'[State] ) )
)
Total = 
CALCULATE (
    SUM ( Requirement[Total] ),
    FILTER ( Requirement, [State] = EARLIER ( 'Data input'[State] ) )
)
Single cost = DIVIDE([Total],[Product Sold])

vzhangti_0-1649063658711.png

Please see the attachment for details.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,One thing missed out sir:

Year range is different could you recheck as per year range.And also sir,How date range is designed in data input?

2022 and 2023 ranges also mentioned over there

Thanks in advance

Hi, @nagasaikumarb22 

 

I have readjusted the data, please check it again.

Column:

Product Sold = 
IF (
    [State] = "TX",
    CALCULATE (
        SUM ( Requirement[Products Sold] ),
        FILTER (
            'Data input',
            [State] = EARLIER ( 'Data input'[State] )
                && [Date] >= "2021/1/1"
                && [Date] <= "2021/3/31"
        )
    ),
    IF (
        [State] = "FL",
        CALCULATE (
            SUM ( Requirement[Products Sold] ),
            FILTER (
                'Data input',
                [State] = EARLIER ( 'Data input'[State] )
                    && [Date] >= "2021/1/1"
                    && [Date] <= "2022/3/31"
            )
        ),
        IF (
            [State] = "CA",
            CALCULATE (
                SUM ( Requirement[Products Sold] ),
                FILTER (
                    'Data input',
                    [State] = EARLIER ( 'Data input'[State] )
                        && [Date] >= "2021/1/1"
                        && [Date] <= "2023/3/31"
                )
            )
        )
    )
)

vzhangti_0-1649065798606.png

Is this the result you want?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

yes its clear.This code is staticly written, now my doubt Can we make it dynamic like if states are many how can we write many IF conditions?

Hi, @nagasaikumarb22 

 

What is the format of your dynamic data? You can provide sample data for reference.

 

Best Regards

 

moizsherwani
Continued Contributor
Continued Contributor

@nagasaikumarb22 this is a PowerBI desktop forum so I think you might be better of asking this in an Excel formum.

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Solution Authors
Top Kudoed Authors