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

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

Reply
MostafaGamal
Helper V
Helper V

How to change the range of sum

Hi All, 

I use the following measure to calclate the No. of Entries for each user and it works fine, but i want the measure to calculate the values in the first 2 rows for each MailOfUser ( this is a column in the table we use )  

Please support how to do this 

 

Capture.PNG

1 ACCEPTED SOLUTION

Hi @MostafaGamal ,

Modify the measure like this:

Re = 
VAR tab =
    SUMMARIZE (
        BOSTrcaking,
        BOSTrcaking[Department],
        BOSTrcaking[Index],
        BOSTrcaking[EntriesCount],
        "count", CALCULATE (
            COUNT ( BOSTrcaking[Department] ),
            FILTER (
                ALL ( BOSTrcaking ),
                'BOSTrcaking'[Department] IN DISTINCT ( 'BOSTrcaking'[Department] )
                    && 'BOSTrcaking'[EntriesTime].[Month]
                        IN DISTINCT ( 'BOSTrcaking'[EntriesTime].[Month] )
                    && 'BOSTrcaking'[MailOFUser] IN DISTINCT ( BOSTrcaking[MailOFUser] )
                    && 'BOSTrcaking'[Index] <= MAX ( 'BOSTrcaking'[Index] )
            )
        )
    )
RETURN
    SUMX ( FILTER ( tab, [count] <= 2 ), [EntriesCount] ) + 0

Result:

1.png2.png

Attached sample file, please check it: Sample.pbix

 

Best Regards,
Yingjie Li

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

18 REPLIES 18
v-yingjl
Community Support
Community Support

Hi @MostafaGamal ,

To get the expected result, need a new column as a row mark of each mailuser.

1. Add an index column manually in power query first:

index column.png

2. Create a new calculated column [Count] as a row mark of each mailuser:

Count =
CALCULATE (
    COUNT ( BOSTrcaking[Department] ),
    FILTER (
        ALLEXCEPT ( BOSTrcaking, BOSTrcaking[Department] ),
        'BOSTrcaking'[Index] <= EARLIER ( BOSTrcaking[Index] )
    )
)

3. Modify your previous measure like this:

Sum =
CALCULATE ( SUM ( BOSTrcaking[EntriesCount] ), 'BOSTrcaking'[Count] <= 2 )

You will get the expected result:

table result.png

 

Attached my sample file that hopes to help you, please check and try it: How to change the range of sum.pbix

 

Best Regards,
Yingjie Li

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

@v-yingjl  i followed the steps you give to me but it gives me this error, please advise 

 

Capture.PNG

Hi @MostafaGamal ,

After creating an index column, you can create a measure directly to try to optimize memory to get the same result:

Re =
VAR tab =
    SUMMARIZE (
        BOSTrcaking,
        BOSTrcaking[Department],
        BOSTrcaking[Index],
        BOSTrcaking[EntriesCount],
        "count", CALCULATE (
            COUNT ( BOSTrcaking[Department] ),
            FILTER (
                ALLEXCEPT ( BOSTrcaking, BOSTrcaking[Department] ),
                'BOSTrcaking'[Index] <= MAX ( 'BOSTrcaking'[Index] )
            )
        )
    )
RETURN
    SUMX ( FILTER ( tab, [count] <= 2 ), [EntriesCount] )

measure.png

 

Best Regards,
Yingjie Li

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

@v-yingjl thanks for youe support, the formula you create gets the result without need to create count column 

but the vaues i get is not what i want, calculate 2 entries for the HSE while it should be 3 entries since one user create 3 entries and another user in the same department HSE create 1 enty that 3 not 2 ( the target is 2 entries so i want to count the first 2 rows for a certain period of time to avoid calculating other users who create more than 2 entries ) 

 

Capture.PNGCapture4.PNG

Hi @MostafaGamal ,

If I got it correctly, modify the measure like this:

Re = 
VAR tab =
    SUMMARIZE (
        BOSTrcaking,
        BOSTrcaking[Department],
        BOSTrcaking[Index],
        BOSTrcaking[EntriesCount],
        "count", CALCULATE (
            COUNT ( BOSTrcaking[Department] ),
            FILTER (
                ALLEXCEPT ( BOSTrcaking, BOSTrcaking[Department], BOSTrcaking[MailOFUser] ),
                'BOSTrcaking'[Index] <= MAX ( 'BOSTrcaking'[Index] )
            )
        )
    )
RETURN
    SUMX ( FILTER ( tab, [count] <= 2 ), [EntriesCount] )

depa1.pngdepartment.png

 

Best Regards,
Yingjie Li

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

@v-yingjl thanks for your response, i have only on last problem that the " EntriesTime " which is date is not affecting the formula 

i want it to count the first 2 rows for every user in the date rane i choose 

 

Hi @MostafaGamal ,

You can create a slicer and put the date field in it to achieve this.

range.png

 

Best Regards,
Yingjie Li

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

 

@v-yingjl  

@v-yingjl  

I already did that but when I change the silcer date it gives blank 

 

The dates in my data starts from 1 July till 31 August 

The formula works fine in July but when I choose auguest in the slicer it gives me blank as there's no values To be counted in this range of time 

Hi @MostafaGamal ,

Since there is no data in August, how could it show the result? 0 or others?

Could you give me an example and expected output based on my sample table so that I could better help you.

dep.png

 

Best Regards,
Yingjie Li

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

@v-yingjl 

there is a values in august but the formula didt see it, here is the table of data i use (below) , you can see that there is values in the clolumn " EntriesCount " 

thats what i expect from the measure a table that count the entries for every user in the first 2 rows 

 

Capture5555.PNG

 

but when i choose the slicer in august it gives me blank 

 

Capture.PNG

 

IndexDepartmentLineNameMailEntriesCount EntriesTime
1HSE Mostafa Gamalmetwaly.mg@pg.com17/1/2020
3HSE Mostafa Gamalmetwaly.mg@pg.com17/14/2020
4HSE Mostafa Gamalmetwaly.mg@pg.com07/15/2020
5HSE Mostafa Gamalmetwaly.mg@pg.com07/16/2020
6HSE Mostafa Gamalmetwaly.mg@pg.com07/17/2020
7HSE Abdullrahman Barakat ali.ab.1@pg.com17/13/2020
8HSE Abdullrahman Barakat ali.ab.1@pg.com07/16/2020
9HSE Abdullrahman Barakat ali.ab.1@pg.com07/17/2020
10HSE Abdullrahman Barakat ali.ab.1@pg.com07/18/2020
11HSE  Nour Abdelaziz abdelaziz.n@pg.com17/12/2020
12HSE  Nour Abdelaziz abdelaziz.n@pg.com17/13/2020
13HSE  Nour Abdelaziz abdelaziz.n@pg.com07/14/2020
14HSE  Nour Abdelaziz abdelaziz.n@pg.com07/15/2020
16FC Hesham Barakatbarakat.hs@pg.com17/13/2020
17FC Hesham Barakatbarakat.hs@pg.com17/17/2020
18FC Hesham Barakatbarakat.hs@pg.com07/16/2020
19FC Hesham Barakatbarakat.hs@pg.com07/22/2020
20FC Sameh Mohammedysameh.ms@pg.com17/12/2020
21FC Sameh Mohammedysameh.ms@pg.com07/13/2020
22FC Sameh Mohammedysameh.ms@pg.com07/31/2020
23HSE Mostafa Gamalmetwaly.mg@pg.com18/1/2020
25HSE Mostafa Gamalmetwaly.mg@pg.com18/14/2020
26HSE Mostafa Gamalmetwaly.mg@pg.com08/15/2020
27HSE Mostafa Gamalmetwaly.mg@pg.com08/16/2020
28HSE Mostafa Gamalmetwaly.mg@pg.com08/17/2020
29HSE Abdullrahman Barakat ali.ab.1@pg.com18/13/2020
30HSE Abdullrahman Barakat ali.ab.1@pg.com18/16/2020
31HSE Abdullrahman Barakat ali.ab.1@pg.com08/17/2020
32HSE Abdullrahman Barakat ali.ab.1@pg.com08/18/2020
33HSE  Nour Abdelaziz abdelaziz.n@pg.com17/12/2020
34HSE  Nour Abdelaziz abdelaziz.n@pg.com18/13/2020
35HSE  Nour Abdelaziz abdelaziz.n@pg.com08/14/2020
36HSE  Nour Abdelaziz abdelaziz.n@pg.com08/15/2020
37FC Hesham Barakatbarakat.hs@pg.com18/1/2020
38FC Hesham Barakatbarakat.hs@pg.com18/13/2020
40FC Hesham Barakatbarakat.hs@pg.com08/16/2020
41FC Hesham Barakatbarakat.hs@pg.com08/22/2020
42FC Sameh Mohammedysameh.ms@pg.com18/12/2020
43FC Sameh Mohammedysameh.ms@pg.com08/13/2020
44FC Sameh Mohammedysameh.ms@pg.com08/31/2020

 

Hi @MostafaGamal ,

Modify the measure like this:

Re = 
VAR tab =
    SUMMARIZE (
        BOSTrcaking,
        BOSTrcaking[Department],
        BOSTrcaking[Index],
        BOSTrcaking[EntriesCount],
        "count", CALCULATE (
            COUNT ( BOSTrcaking[Department] ),
            FILTER (
                ALL ( BOSTrcaking ),
                'BOSTrcaking'[Department] IN DISTINCT ( 'BOSTrcaking'[Department] )
                    && 'BOSTrcaking'[EntriesTime].[Month]
                        IN DISTINCT ( 'BOSTrcaking'[EntriesTime].[Month] )
                    && 'BOSTrcaking'[MailOFUser] IN DISTINCT ( BOSTrcaking[MailOFUser] )
                    && 'BOSTrcaking'[Index] <= MAX ( 'BOSTrcaking'[Index] )
            )
        )
    )
RETURN
    SUMX ( FILTER ( tab, [count] <= 2 ), [EntriesCount] ) + 0

Result:

1.png2.png

Attached sample file, please check it: Sample.pbix

 

Best Regards,
Yingjie Li

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

 

Hi @MostafaGamal ,

Please try to release your pc memory or filter the data table without unnecessary data.

 

Best Regards,
Yingjie Li

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

 

parry2k
Super User
Super User

@MostafaGamal what identifies the first two-lines, it has to be business logic, not plain English.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  thanks for your reply, But i dont understand what you mean by not plain english ? 

@MostafaGamal you mentioned the first two lines, doesn't mean anything until you provide the business logic. I hope it clarifies.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  Every row have a uniqe identefires which is the ( Mail of user ) and since every user have almost like 60 rows i would like to sum the values in the first 2 rows for every user not the sum of all 60 rows 

I hope that i made myself clear ? 

@MostafaGamal ok , again what is first tow rows, sorted by date, some id  or what?

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  they will be sorted by the mail of the user as its s special for every user in this database 

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.