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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors