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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ebbrey
Frequent Visitor

SUMX with filter using SELECTEDVALUE

Hey

 

Im fairly new to Power BI and im trying to solve SUMX to a non-related table.

 

The table im trying to get correct number from has info like this:

Elements Table:

ProjectnumberCode2Start DateEnd DateDemand
1234567810.10.1001.01.201931.12.20196
1234567910.10.1115.07.201931.12.20196
9876543210.10.1001.01.201915.07.202012

 

In my visuals this table works great, since it filters on Project number. And i dont get issues at all. But i cant pull the data based on project number into power bi, I have to get this list with everything in it.

 

I have made a calendar that uses First date from Start Date and last date from End date. Then made new colums adding:

Calendar = CALENDAR([FirstDate];[LastDate])
Week = if(WEEKDAY('Calendar'[Date];2)=1;WEEKNUM('Calendar'[Date]);BLANK())
Year = 
year('Calendar'[Date])
Year-Week= IF('Calendar'[Week]<>BLANK();'Calendar'[YEAR]&"-"&'Calendar'[WEEK];Blank())
 
Then i removed blank() rows in Week. I need a new column into this calendar table that pulls Demand from elements table so i can show the weeks and what the demand is in that week for the current selected project.

I have tried this so far for a new column:
 
Demand =
IF('Calendar'[Year-Week]=BLANK();BLANK();
CALCULATE(
sumx(filter('Elements';Elements[Projectnumber]="12345678");Elements[Demand]);
'Elements'[Start Date] <= EARLIER ( 'Calendar'[Date] );
'Elements'[End Date] >= EARLIER ( 'Calendar'[Date] )))

1.png
 
This works. But not based on the current selected project. As i have written the number in. 
 
i wish this worked:
 
Demand =
IF('Calendar'[Year-Week]=BLANK();BLANK();
CALCULATE(
sumx(filter('Elements';Elements[Projectnumber]=SELECTEDVALUE(Projectlist[Number]));Elements[Demand]); 
'Elements'[Start Date] <= EARLIER ( 'Calendar'[Date] );
'Elements'[End Date] >= EARLIER ( 'Calendar'[Date] )))
 
Thanks for any input on how to solve this.
1 ACCEPTED SOLUTION
lc_finance
Solution Sage
Solution Sage

Hi @ebbrey ,

 

 

To have the measure based on the currently selected project, you'd need to use a calculated measure instead of a calculated column.

Does this help you?

 

If it doesn't, can you share a sample Power BI file?

You can share it via One Drive, Google Drive or a similar tool.

 

Regards,

 

LC

Interested in Power BI and DAX templates? Check out my blog at www.finance-bi.com

View solution in original post

3 REPLIES 3
lc_finance
Solution Sage
Solution Sage

Hi @ebbrey ,

 

 

To have the measure based on the currently selected project, you'd need to use a calculated measure instead of a calculated column.

Does this help you?

 

If it doesn't, can you share a sample Power BI file?

You can share it via One Drive, Google Drive or a similar tool.

 

Regards,

 

LC

Interested in Power BI and DAX templates? Check out my blog at www.finance-bi.com

@lc_finance 

 

Thanks for your reply to my question and pointing me away from trying to use selectedvalue in a column.

 

I ended up getting it to work by using a referance table wich i could relate to the project table and get the filter i needed.

I'm glad you found a solution for it!

 

Do not hesitate if you have more questions.

 

LC

Interested in Power BI and DAX tutorials? Check out my blog at www.finance-bi.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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