Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone,
I'm trying to create a measure with 2 date column but with a little twist..
Sold Date | Status | Cancelation Date | Price |
Jan | Sold | $10 | |
Jan | Canceled | Feb | $10 |
Feb | Sold | $10 |
The ''Sold Date'' is linked to a date fact table. If you select January the total amount should be $20 (based on Sold Date) and if you select February, because there is a cancelation date, the amount need to be substracted from this month. Total for February should be $0. Any idea how to create a measure like that?
Thank you for your help!
Solved! Go to Solution.
Please try this measure in a table visual with your Sold Date column. Replace Sold with your actual table name throughout.
Total Sold =
VAR thismonth =
SELECTEDVALUE ( Sold[Sold Date] )
VAR sales =
CALCULATE ( SUM ( Sold[Price] ), Sold[Status] = "Sold" )
VAR cancels =
CALCULATE (
SUM ( Sold[Price] ),
Sold[Status] = "Canceled",
ALL ( Sold ),
Sold[Cancelation Date] = thismonth
)
RETURN
sales - cancels
Also, to get the right total, make the measure above and then use this measure in the visual.
Sales Right Total = SUMX(VALUES(Sold[Sold Date]), [Total Sold])
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
@Anonymous
Can you share some sample data and the expected result to have a clear understanding of your question?
You can save your files in OneDrive, Google Drive, or any other cloud sharing platforms and share the link here.
____________________________________
How to paste sample data with your question?
How to get your questions answered quickly?
_____________________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you @Fowmy Here's the link: https://drive.google.com/file/d/1thQdeZO9yuEnW5U4EOzGdlym9RIK57r0/view?usp=sharing
Based on the Date table, if you select January the total should be $20 (based on Sold Date column). If you choose february the total should be $0 ($10 sold in Feb - $10 from the cancelation of February). If you don't select any month, the total should be $10.
@Anonymous
Try this measure:
Measure =
VAR D = FORMAT(MAX('Date'[Date]),"YYYYMM")
VAR _CANCELLED =
SUMX(
FILTER(
ALL(Sold),
FORMAT(Sold[Cancelation date],"YYYYMM") = D
),
[_SUM]
)
RETURN
IF( HASONEVALUE('Date'[Date].[Mois]),
[_SUM] - _CANCELLED,
SUMX(
ALL(Sold),
IF( Sold[Status] = "Sold", Sold[Price] , Sold[Price] * -1)
)
)
________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you @Fowmy for your time.
I'm not sure how the [_SUM] should work... it's looking for a column called _SUM but there's none....
@Anonymous
I forgot to include that measure:
You can download the file: HERE
_SUM = SUM(Sold[Price])
________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon if you like this reply 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Please try this measure in a table visual with your Sold Date column. Replace Sold with your actual table name throughout.
Total Sold =
VAR thismonth =
SELECTEDVALUE ( Sold[Sold Date] )
VAR sales =
CALCULATE ( SUM ( Sold[Price] ), Sold[Status] = "Sold" )
VAR cancels =
CALCULATE (
SUM ( Sold[Price] ),
Sold[Status] = "Canceled",
ALL ( Sold ),
Sold[Cancelation Date] = thismonth
)
RETURN
sales - cancels
Also, to get the right total, make the measure above and then use this measure in the visual.
Sales Right Total = SUMX(VALUES(Sold[Sold Date]), [Total Sold])
If this works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
10 | |
6 |