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
Pedro503
Resolver I
Resolver I

Computing values between a range of dates

Hey there


Here's the link for my sample file.

 

How can I compute the amount of sales for a given user, but respecting their active date period? For instance, taking the IdUser = 1 into consideration a correct measure should computes the total of 278, as his active period (shown in d_users table) is from January 1st, 2020 to February 19th, 2020, therefore excluding the sales that took place after this period, i.e., IdSale = 16 and IdSale = 19.

 

For this specific case, I've authored the following measure, but it has not worked in the total level, only in the row level.

 

Modelo = 
VAR _Maximo = MAX( d_calendar[Date] )
VAR _Minimo = MIN( d_calendar[Date] )
VAR _Periodo =
    DATESBETWEEN(
        d_calendar[Date],
        CALCULATE( MIN( d_users[DateStart] ) ),
        CALCULATE( MIN( d_users[DateEnd] ) )
    )
VAR _UsersAtivos =
    SUMMARIZE(
        FILTER(
            d_users,
            d_users[DateStart] <= _Maximo
                && d_users[DateEnd] >= _Minimo
        ),
        d_users[IdUser]
    )
VAR _Resultado =
    CALCULATE(
        SUMX( f_sales, f_sales[Amount] ),
        KEEPFILTERS( _UsersAtivos )
    )
RETURN
    _Resultado


The other calculation I'd like to compute is basically the same, however now the date period is stored at f_users. In this calculation, only the IdSale = 16 should not be take into consideration as the IdSale = 19 took place in his second active period at f_users.

 

Could you guys help me out with this? @SpartaBI @Ahmedx @Ritaf1983 

 

Thanks in advance.

7 REPLIES 7
v-shex-msft
Community Support
Community Support

Hi @Pedro503 ,

Any update for this? Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hey there.

 

I've tried all the responses, but none of them actually worked.

danextian
Super User
Super User

Hi @Pedro503 ,

 

Please try this:

Sales within active period = 
CALCULATE (
    SUM ( f_sales[Amount] ),
    FILTER (
        f_sales,
        f_sales[DateSale] >= MIN ( d_users[DateStart] )
            && f_sales[DateSale] <= MAX ( d_users[DateEnd] )
    ),
    CROSSFILTER ( d_users[IdUser], f_sales[IdUser], NONE )
)

danextian_0-1702176697748.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hey, @danextian . Thanks a lot for your response.

 

I've tried replicatig this measure you provide but there are some row-level numbers that don't seem to be right, as outlined in the following image. In this specific case, the number 93 is a sale from IdUser = 1, but in this week this user was not active. Do you know why it happens? However, you manage to fix the total-level result, which is great for my case. Thanks for that.

Pedro503_0-1702235144898.png

 

Also, do you know how to make the calculation for the 'f_user' table? There there are more than one row for each IdUser, therefore making things even more difficult (which unfortunely happens in my real-life model).

 

Once again, I do appreciate your help.

Ashish_Mathur
Super User
Super User

Hi,

Darag this measure to the visual

Modelo1 = SUMX(VALUES(d_calendar[Week]),[Modelo])

Hope this helps.

Ashish_Mathur_0-1702176247517.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey, @Ashish_Mathur . Thanks for your response.

 

Great, it has actually worked.

 

Do you know how to compute the second part?

 

The other calculation I'd like to compute is basically the same, however now the date period is stored at f_users. In this calculation, only the IdSale = 16 should not be take into consideration as the IdSale = 19 took place in his second active period at f_users.

 

My real-life model has this particularity, but I don't know how to solve this either.

 

Once again, thanks for your response.

I just cannot understand your requirement.  Share a simple dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.