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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
farzadvhd
Frequent Visitor

DAX based on the min and max of the selected values in Slicer

I have a calculated column and I want it to be based on the minimum and maximum value selected from the slicer. In fact this formula should work also with the min and max of the slicer instead of the fixed dates. I also attached the sample of the .pbix data HERE

quantity_sum_correct = 
VAR SelectedStartDate = DATE(2023,2,1)
VAR SelectedEndDate = DATE(2023,3,1)
RETURN
SUMX(
    FILTER(
        RELATEDTABLE(Quantity),
        Quantity[Date] >= SelectedStartDate &&
        Quantity[Date] <= SelectedEndDate),
    Quantity[quantity]
    )

 

2 ACCEPTED SOLUTIONS

Hi @farzadvhd ,

 

govindarajan_d_0-1706784885876.png

I see that there is many-to-many relationship between quantity and metal. And this causes duplicates in the table because there is no date column in the metals table. The row duplicates itself for each date that is present in the quantity table. Is this what you want?

 

During totals, Power BI calculates the sum by having no row level filter on the formula. That is why you are getting 1190.

But I cannot understand how you want the sum to be. Please provide more details. 

View solution in original post

Anonymous
Not applicable

Hi @farzadvhd ,

I’ve read through the thread and I see that @govindarajan_d has already provided some insightful responses. 👍

Since you created a calculated column, and it will not change according to the user interaction(slicer, filter, column selections etc.) in the report as the value of a calculated column is computed during data refresh and uses the current row as a context... Please review the following links about the difference of calculated column and measure...

Calculated Columns and Measures in DAX

Calculated Columns vs Measures

So if you want to get the dynamic value base on the selected values, you need to create a measure as below to replace the original calculated column. Please find the details in the attachment.

Measure = 
VAR SelectedStartDate =
    MIN ( Quantity[Date] )
VAR SelectedEndDate =
    MAX ( Quantity[Date] )
RETURN
    SUMX (
        FILTER (
            Quantity,
            Quantity[Date] >= SelectedStartDate
                && Quantity[Date] <= SelectedEndDate
        ),
        Quantity[quantity]
    )
        * SUM ( Metals[Gram] )
pz*gr = SUMX ( GROUPBY ( 'Metals', 'Metals'[key], 'Metals'[Metal] ), [Measure] )

vyiruanmsft_0-1706861052794.png

Best Regards

View solution in original post

5 REPLIES 5
govindarajan_d
Super User
Super User

Hi @farzadvhd ,

Calculated columns cannot access slicer value. Is there any specific reason you are using Calculated columns instead of measures? Can the same logic be replicated as a measure (which is more efficient in terms of performance)?

@govindarajan_d when I am using measure the total would not be correct, however the values in each row (considering a table in report view) are correct. I appreciate it if you could take a look at the sample I attached to see if there is any other way

Hi @farzadvhd ,

 

govindarajan_d_0-1706784885876.png

I see that there is many-to-many relationship between quantity and metal. And this causes duplicates in the table because there is no date column in the metals table. The row duplicates itself for each date that is present in the quantity table. Is this what you want?

 

During totals, Power BI calculates the sum by having no row level filter on the formula. That is why you are getting 1190.

But I cannot understand how you want the sum to be. Please provide more details. 

In fact the Metal table does not have any date because it contains different Metals for each Article. So they are in multiple rows and I want the sum to consider these duplicates,  Above all I need pz*gr 

I already solved the issue in Excel
By creating a pivot table and xlookup of pivoted table, but I don't know how to apply it in power BI.

Thanks a lot for your help

Anonymous
Not applicable

Hi @farzadvhd ,

I’ve read through the thread and I see that @govindarajan_d has already provided some insightful responses. 👍

Since you created a calculated column, and it will not change according to the user interaction(slicer, filter, column selections etc.) in the report as the value of a calculated column is computed during data refresh and uses the current row as a context... Please review the following links about the difference of calculated column and measure...

Calculated Columns and Measures in DAX

Calculated Columns vs Measures

So if you want to get the dynamic value base on the selected values, you need to create a measure as below to replace the original calculated column. Please find the details in the attachment.

Measure = 
VAR SelectedStartDate =
    MIN ( Quantity[Date] )
VAR SelectedEndDate =
    MAX ( Quantity[Date] )
RETURN
    SUMX (
        FILTER (
            Quantity,
            Quantity[Date] >= SelectedStartDate
                && Quantity[Date] <= SelectedEndDate
        ),
        Quantity[quantity]
    )
        * SUM ( Metals[Gram] )
pz*gr = SUMX ( GROUPBY ( 'Metals', 'Metals'[key], 'Metals'[Metal] ), [Measure] )

vyiruanmsft_0-1706861052794.png

Best Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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