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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Belarminio
Frequent Visitor

Trying to get a value from the first week in a graph from a pivot table to use as baseline

i'm looking to graph this pic below the baseline line has to be a value from the first week. This formula does the trick

CALCULATE(SUM('All Weekly Data'[Bodies for Week]),ALLSELECTED('All Weekly Data'),'All Weekly Data'[Source]="Current",'All Weekly Data'[Week Ends] = DATE(2022,3,12) )

however i need it to be dinamic and since i'm hard coding the Date(2022,3,12) that not posible.

i have tried a number of combinations of Filter funtion and i can't get anything to work. any help would be much appreciated.

 

Belarminio_0-1669910764877.png+

Belarminio_1-1669911062263.png

 

 

1 ACCEPTED SOLUTION

Thanks every one for your help the answer you provided makes absolute sense but still it give me an error.  I tried several things and again not sure why these solutions don’t work because the look logical.  If that works for you the error may have something to do with the version of power BI I use I am really not sure but I tried that variation and still got an error. The error happens because of this section 'All (Weekly Data'[Week Ends] = _MINDATE  it just wont take it.

Happily I have tried enough spaghetti in the wall that something finally stuck. This solution actually worked.  

 

First Week:=if(CALCULATE(MIN('All Weekly Data'[Week Ends]),ALLSELECTED('All Weekly Data')) = MIN('All Weekly Data'[Week Ends]),MIN('All Weekly Data'[Week Ends]),BLANK())

 

Cost - Base Line:=CALCULATE(SUM('All Weekly Data'[Cost for Week]),FILTER(ALLSELECTED('All Weekly Data'),'All Weekly Data'[Week Ends]=[First Week]), 'All Weekly Data'[Source]= "Current")

 

Belarminio_0-1670005864013.png

 

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@Belarminio Maybe:

Measure =
  VAR __Date = MIN('All Weekly Data'[Week Ends])
  VAR __Result =  
CALCULATE(SUM('All Weekly Data'[Bodies for Week]),ALLSELECTED('All Weekly Data'),'All Weekly Data'[Source]="Current",'All Weekly Data'[Week Ends] = __Date )
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thanks for your reply Greg i did not mentioned that i tryed that before and i get an error when i do. i think that your example is from Power BI, how ever i'm using the DAX in Powere Pivot.

Var 1:=CALCULATE(MIN('All Weekly Data'[Week Ends]),ALLSELECTED('All Weekly Data'[Week Ends]))

 

Var 2:=CALCULATE(SUM('All Weekly Data'[Bodies for Week]),ALLSELECTED('All Weekly Data'),'All Weekly Data'[Source]="Current",'All Weekly Data'[Week Ends] = [Var 1] )

 

Belarminio_0-1669918240085.png

if i use this formula 

Var 2:=CALCULATE(SUM('All Weekly Data'[Bodies for Week]),ALLSELECTED('All Weekly Data'),'All Weekly Data'[Source]="Current",FILTER('All Weekly Data','All Weekly Data'[Week Ends] = [Var 1] ))

Then i get this result.. as you can see the the date is fine in the Var 1 column, but the Var 2 is still not giving me the the number in the 1st week... for some reason not clear to me the ALLSELECTED funtion is bein cancelled by the FILTER funtion somehow.

Belarminio_1-1669919257816.png

 

 

Hi @Belarminio ,

 

Here I suggest you to try this code.

Measure =
VAR _MINDATE =
    CALCULATE (
        MIN ( 'All Weekly Data'[Week Ends] ),
        FILTER ( ALL ( 'All Weekly Data' ), 'All Weekly Data'[Source] = "Current" )
    )
RETURN
    CALCULATE (
        SUM ( 'All Weekly Data'[Bodies for Week] ),
        ALLSELECTED ( 'All Weekly Data' ),
        'All Weekly Data'[Source] = "Current",
        'All Weekly Data'[Week Ends] = _MINDATE
    )


Best Regards,
Rico Zhou

 

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

Thanks every one for your help the answer you provided makes absolute sense but still it give me an error.  I tried several things and again not sure why these solutions don’t work because the look logical.  If that works for you the error may have something to do with the version of power BI I use I am really not sure but I tried that variation and still got an error. The error happens because of this section 'All (Weekly Data'[Week Ends] = _MINDATE  it just wont take it.

Happily I have tried enough spaghetti in the wall that something finally stuck. This solution actually worked.  

 

First Week:=if(CALCULATE(MIN('All Weekly Data'[Week Ends]),ALLSELECTED('All Weekly Data')) = MIN('All Weekly Data'[Week Ends]),MIN('All Weekly Data'[Week Ends]),BLANK())

 

Cost - Base Line:=CALCULATE(SUM('All Weekly Data'[Cost for Week]),FILTER(ALLSELECTED('All Weekly Data'),'All Weekly Data'[Week Ends]=[First Week]), 'All Weekly Data'[Source]= "Current")

 

Belarminio_0-1670005864013.png

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Power BI Header Change

Power BI Header Update

Read about the exciting updates for the Power BI forum.

Top Solution Authors