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
colourfullife
Post Partisan
Post Partisan

Don't Sum if there is no Date value

Hi All,

i need your help.

 

i have this code below.

i don't want to sum PO Line Quantity if there is no dates in CDD

 

1. CDD =
VAR _End = CALCULATE ( MAX ( 'SPARES - PO STATUS'[CDD] ), ALL ( 'calendar' ))
RETURN
    IF (
        _End < MIN ( 'calendar'[Date] ),
        BLANK (),
CALCULATE(
    Sum('SPARES - PO STATUS'[PO_LINE_QUANTITY]), USERELATIONSHIP('SPARES - PO STATUS'[CDD],'calendar'[Date]),
    FILTER(
        ALLSELECTED('calendar'[Date]),
        ('calendar'[Date] <= MAX('calendar'[Date])))))
 
now the graph look funny as below.
aaaasss.PNG
 
any advice would be much appreciated.
 
thank you,
CL
7 REPLIES 7
amitchandak
Super User
Super User

@colourfullife , not very clear, Try two modification

 


CDD =
VAR _End = CALCULATE ( MAX ( 'SPARES - PO STATUS'[CDD] ), ALL ( 'calendar' ), USERELATIONSHIP('SPARES - PO STATUS'[CDD],'calendar'[Date]))
RETURN
IF (
_End < MIN ( 'calendar'[Date] ) || isblank(MAX ( 'SPARES - PO STATUS'[CDD] )),
BLANK (),
CALCULATE(
Sum('SPARES - PO STATUS'[PO_LINE_QUANTITY]), USERELATIONSHIP('SPARES - PO STATUS'[CDD],'calendar'[Date]),
FILTER(
ALLSELECTED('calendar'[Date]),
('calendar'[Date] <= MAX('calendar'[Date])))))

 

or

 


CDD =
VAR _End = CALCULATE ( MAX ( 'SPARES - PO STATUS'[CDD] ), USERELATIONSHIP('SPARES - PO STATUS'[CDD],'calendar'[Date]))
RETURN
IF (
_End < MIN ( 'calendar'[Date] ) || isblank(MAX ( 'SPARES - PO STATUS'[CDD] )),
BLANK (),
CALCULATE(
Sum('SPARES - PO STATUS'[PO_LINE_QUANTITY]), USERELATIONSHIP('SPARES - PO STATUS'[CDD],'calendar'[Date]),
FILTER(
ALLSELECTED('calendar'[Date]),
('calendar'[Date] <= MAX('calendar'[Date])))))

thanks for your reply

 

i got this result with both codes

hmm.PNG

Hi @colourfullife,

Maybe you can break the relationship between fact table and calendar, then you can use calendar date as axis with the following measure formula as value:

CDD =
VAR _End =
    MAXX ( ALL ( 'SPARES - PO STATUS' ), 'SPARES - PO STATUS'[CDD] )
VAR currDate =
    MAX ( 'calendar'[Date] )
RETURN
    IF (
        currDate <= _End,
        CALCULATE (
            SUM ( 'SPARES - PO STATUS'[PO_LINE_QUANTITY] ),
            FILTER (
                ALLSELECTED ( 'SPARES - PO STATUS' ),
                'SPARES - PO STATUS'[CDD] <= MAX ( 'calendar'[Date] )
            )
        )
    )

If above not help, please provide some dummy data with raw table structure then we can do test to coding formula.

How to Get Your Question Answered Quickly 
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi,

i think it's not working as i want.

attached link for dummy file.

dummy file

thank you,

CL

Hi @colourfullife,

I can't open the sample file on my side, it should the file probably be encrypted or corrupted. Can you please fix this?

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft  

 

please check this one : LINK 

 

Regards,

CL

Hi @colourfullife,

So you mean you only want to show the data point without any aggregate if fact table 'cod' fields do not exist on the calendar table? If this is a case, you can remove '<' operator to only display the data point on correspond calendar dates.

CDD =
VAR _End =
    MAXX ( ALL ( 'SPARES - PO STATUS' ), 'SPARES - PO STATUS'[CDD] )
VAR currDate =
    MAX ( 'calendar'[Date] )
RETURN
    IF (
        currDate <= _End,
        CALCULATE (
            SUM ( 'SPARES - PO STATUS'[PO_LINE_QUANTITY] ),
            FILTER (
                ALLSELECTED ( 'SPARES - PO STATUS' ),
                'SPARES - PO STATUS'[CDD] = MAX ( 'calendar'[Date] )
            )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.