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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
trathman
Regular Visitor

Summing a Range Based on Serial Numbers

I have a serial number column that is based on 3 different sets of numbers. The first set (A) is four digit, the second (B) and third (C) set are 2 digits. To create the serial number I apply the following transformation:
A*10000+B*100+C = AAAABBCC
Am I able to create a measure that is:
VAR SerialStart = SerialStart (Coming from different slicer selections based on A, B, C)
VAR SerialEnd = SerialEnd (Coming from different slicer selections based on A, B', C')

CALCULATE(
SUM('BookDtl'[BookAmt]),
FILTER('BookDtl',
            'BookDtl'[Serial] >= SerialStart &&
            'BookDtl'[Serial] <= SerialEnd
           )
)

What is my error? 
 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

 

Hi @trathman ,
Thanks for Ashish_Mathur and DataNinja777 replies and efforts.

Based on your description and their suggestions, here is the sample data and MEASURE I created

vheqmsft_0-1739843199191.png

To make sure  slicer works, there should be no relationship between the tables

vheqmsft_1-1739843282888.png

Create a measure

Total = 
VAR SerialStart = 
    SELECTEDVALUE(SlicerTableA[ValueA]) * 10000 +
    SELECTEDVALUE(SlicerTableB[ValueB]) * 100 +
    SELECTEDVALUE(SlicerTableC[ValueC])

VAR SerialEnd = 
    SELECTEDVALUE(SlicerTableA[ValueA]) * 10000 +
    SELECTEDVALUE('SlicerTableB'''[ValueB']) * 100 +
    SELECTEDVALUE('SlicerTableC'''[ValueC'])

RETURN
CALCULATE(
    SUM(BookDtl[BookAmt]),
    FILTER(
        BookDtl,
        BookDtl[Serial] >= SerialStart &&
        BookDtl[Serial] <= SerialEnd
    )
)

Final output

vheqmsft_2-1739843337575.pngvheqmsft_3-1739843337618.png

 

Best regards,
Albert He


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

5 REPLIES 5
Anonymous
Not applicable

 

Hi @trathman ,
Thanks for Ashish_Mathur and DataNinja777 replies and efforts.

Based on your description and their suggestions, here is the sample data and MEASURE I created

vheqmsft_0-1739843199191.png

To make sure  slicer works, there should be no relationship between the tables

vheqmsft_1-1739843282888.png

Create a measure

Total = 
VAR SerialStart = 
    SELECTEDVALUE(SlicerTableA[ValueA]) * 10000 +
    SELECTEDVALUE(SlicerTableB[ValueB]) * 100 +
    SELECTEDVALUE(SlicerTableC[ValueC])

VAR SerialEnd = 
    SELECTEDVALUE(SlicerTableA[ValueA]) * 10000 +
    SELECTEDVALUE('SlicerTableB'''[ValueB']) * 100 +
    SELECTEDVALUE('SlicerTableC'''[ValueC'])

RETURN
CALCULATE(
    SUM(BookDtl[BookAmt]),
    FILTER(
        BookDtl,
        BookDtl[Serial] >= SerialStart &&
        BookDtl[Serial] <= SerialEnd
    )
)

Final output

vheqmsft_2-1739843337575.pngvheqmsft_3-1739843337618.png

 

Best regards,
Albert He


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

 

 

 

Ashish_Mathur
Super User
Super User

Hi,

In Power Query, ensure that the data type of the Serial number column is number.  This measure should work

Measure = calculate(SUM('BookDtl'[BookAmt]),'BookDtl'[Serial]>=min('BookDtl'[Serial])&&'BookDtl'[serial]<=max('BookDtl'[Serial]))

If this does not work, then share the download link of the PBI file and show the expected result very clearly.


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

Hi @trathman ,

 

Your error likely comes from how SerialStart and SerialEnd are being defined, as they need to be properly extracted from the slicer selections. If each part of the serial number (A, B, and C) is selected separately for both the start and end values, they should be referenced correctly. Additionally, the FILTER function must be applied to the correct table to ensure that only the relevant range is considered. Below is the corrected measure.

VAR SerialStart = 
    SELECTEDVALUE('SlicerTable'[A_Start]) * 10000 +
    SELECTEDVALUE('SlicerTable'[B_Start]) * 100 +
    SELECTEDVALUE('SlicerTable'[C_Start])

VAR SerialEnd = 
    SELECTEDVALUE('SlicerTable'[A_End]) * 10000 +
    SELECTEDVALUE('SlicerTable'[B_End]) * 100 +
    SELECTEDVALUE('SlicerTable'[C_End])

RETURN
CALCULATE(
    SUM('BookDtl'[BookAmt]),
    FILTER(
        'BookDtl',
        'BookDtl'[Serial] >= SerialStart &&
        'BookDtl'[Serial] <= SerialEnd
    )
)

This measure constructs the SerialStart and SerialEnd values using the SELECTEDVALUE function, which retrieves the selected number from each slicer. The calculation follows the AAAABBCC format by multiplying the values accordingly. The FILTER function is then applied to 'BookDtl' to ensure that only serial numbers within the specified range contribute to the total sum of BookAmt. If multiple selections are allowed in the slicers, MIN and MAX can be used instead of SELECTEDVALUE to avoid blank values when multiple options are chosen. This approach ensures that the filtering logic works correctly across different slicer selections.

 

Best regards,

I am still getting nothing in the table visual. Can you expand on MIN and MAX? I've only been working with Power BI for about a year.

Thank you for the suggestion and I will try it and let you know what happens. I should refine what I had as  Variables SerialStart and SerialEnd refer to measures that were defined as:

SerialStart=

VAR ASerial = SELECTEDVALUE('SlicerTableA'[ValueA])
VAR BSerial = SELECTEDVALUE('SlicerTableB'[ValueB])
VAR CSerial = SELECTEDVALUE('SlicerTableC'[ValueC])

VAR Result = (ASerial*10000)+(BSerial*100)+CSerial

RETURN Result

 

Same structure for SerialEnd, using different slicer tables.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors