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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
harib
Post Patron
Post Patron

How to sum sales with comparing 2 column dates

HI 

I would like to to get the sum of PROFITABLE_OUTLETS with comparing "DATE_MOC" and "ECO_MOC_DATE" dates fields  .  

 

Capture.JPG

Below formula used in Tableau.

PO= SUM(IF (YEAR([Date_Moc]) = YEAR([ ECO_MOC_Date])

and MONTH([Date_Moc]) = MONTH([ ECO_MOC_Date]))

THEN  [PROFITABLE_OUTLETS] ELSE 0 END)

 

If i implement same logic in powerbi , not getting "ECO_MOC_1" field in year and month section.

PO =
VAR PO=
CALCULATE(SUM([PROFITABLE_OUTLETS]),
AND(
MONTH([Date_Moc])=MONTH(XXXXX),
YEAR([Date_Moc])=YEAR(XXXXX)))
RETURN IF(ISBLANK(PO),0,PO)

 

Please let me know how to get this

 

Thanks in advance

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @harib 

 

If you need a new column, you could try:

 

PO Column =
IF (
    YEAR ( 'Table'[Date_Moc] ) = YEAR ( 'Table'[ECO_MOC_Date] )
        && MONTH ( 'Table'[Date_Moc] ) = MONTH ( 'Table'[ECO_MOC_Date] ),
    'Table'[PROFITABLE_OUTLETS],
    0
)

 

121403.jpg 

 

If you need a measure, you could try:

 

PO Measure = 
IF (
    MONTH ( SELECTEDVALUE ( 'Table'[Date_Moc] ) )
        = MONTH ( SELECTEDVALUE ( 'Table'[ECO_MOC_Date] ) )
        && YEAR ( SELECTEDVALUE ( 'Table'[Date_Moc] ) )
            = YEAR ( SELECTEDVALUE ( 'Table'[ECO_MOC_Date] ) ),
    SUM ( 'Table'[PROFITABLE_OUTLETS] ),
    0
)

 

121404.jpg

 

Is this what you want?

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @harib 

 

If you need a new column, you could try:

 

PO Column =
IF (
    YEAR ( 'Table'[Date_Moc] ) = YEAR ( 'Table'[ECO_MOC_Date] )
        && MONTH ( 'Table'[Date_Moc] ) = MONTH ( 'Table'[ECO_MOC_Date] ),
    'Table'[PROFITABLE_OUTLETS],
    0
)

 

121403.jpg 

 

If you need a measure, you could try:

 

PO Measure = 
IF (
    MONTH ( SELECTEDVALUE ( 'Table'[Date_Moc] ) )
        = MONTH ( SELECTEDVALUE ( 'Table'[ECO_MOC_Date] ) )
        && YEAR ( SELECTEDVALUE ( 'Table'[Date_Moc] ) )
            = YEAR ( SELECTEDVALUE ( 'Table'[ECO_MOC_Date] ) ),
    SUM ( 'Table'[PROFITABLE_OUTLETS] ),
    0
)

 

121404.jpg

 

Is this what you want?

Community Support Team _ Jing Zhang
If this post helps, please consider Accept it as the solution to help other members find it.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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