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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
williamy281
Frequent Visitor

Dax Formula to Calculate population from min date and max date

Hi,

  Another newbie to Power BI.   I'm trying to calculate the difference in population between the min and max dates.

May data is set up like this:

 Facility      date                 pop_cnt

denver      3/1/2019           10,000

denver      4/1/2019           12,000

denver      5/1/2019           14,000

boulder    3/1/2019              3,0000

boulder    4/1/2019              5,0000

boulder    5/1/2019              7,0000

 

So, what I need to know is the difference in denver's population between march and may 2019 (14,000 - 10,000 = 4,000, then 4,000/10,000 = 4%) . Same thing for boulder.  How do I do this in DAX ?

Thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I'm not entirely sure what you want (a measure, a calculated column?) but this might do what you want or might be close enough so that you can tweak it:

[Your Measure] :=
var __isOneFacilityVisible =  HASONEFILTER( FactTable[Facility] )
var __currentFacility = values( FactTable[Facility]
var __minDate =
    CALCULATE(
        min( FactTable[date] ),
        FactTable[Facility] = __currentFacility,
        ALLSELECTED()
    )
var __maxDate =
    CALCULATE(
        max( FactTable[date] ),
        FactTable[Facility] = __currentFacility,
        ALLSELECTED()
    )    
var __populationForMinDate =
    CALCULATE(
        VALUES( Table[pop_cnt] ),
        FactTable[Facility] = __currentFacility,
        FactTable[date] = __minDate,
        ALLSELECTED()        
    )
var __populationForMaxDate =
    CALCULATE(
        VALUES( Table[pop_cnt] ),
        FactTable[Facility] = __currentFacility,
        FactTable[date] = __maxDate,
        ALLSELECTED()        
    )
return
    if(
        __isOneFacilityVisible,
        __populationForMaxDate - __populationForMinDate 
    )

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

I'm not entirely sure what you want (a measure, a calculated column?) but this might do what you want or might be close enough so that you can tweak it:

[Your Measure] :=
var __isOneFacilityVisible =  HASONEFILTER( FactTable[Facility] )
var __currentFacility = values( FactTable[Facility]
var __minDate =
    CALCULATE(
        min( FactTable[date] ),
        FactTable[Facility] = __currentFacility,
        ALLSELECTED()
    )
var __maxDate =
    CALCULATE(
        max( FactTable[date] ),
        FactTable[Facility] = __currentFacility,
        ALLSELECTED()
    )    
var __populationForMinDate =
    CALCULATE(
        VALUES( Table[pop_cnt] ),
        FactTable[Facility] = __currentFacility,
        FactTable[date] = __minDate,
        ALLSELECTED()        
    )
var __populationForMaxDate =
    CALCULATE(
        VALUES( Table[pop_cnt] ),
        FactTable[Facility] = __currentFacility,
        FactTable[date] = __maxDate,
        ALLSELECTED()        
    )
return
    if(
        __isOneFacilityVisible,
        __populationForMaxDate - __populationForMinDate 
    )

I'll have to try this, but I think it's what I need.  Yes, I was trying to create a measure for this.

Thank you.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.