How do I create zeros for null values in line chart?

I'm importing a SQL query that data and have included a batch date transform at the workbench level. I've joined the SQL query to the Calendar dataset so that dates are created for any weeks missing data which I was hoping would give me a 0 line on my chart for those days, but its not working.  I've done this successfully in two other cases, but the difference in those cases was that the imported data was from Salesforce. 

 

I've tried this in beast mode but that gives me an error: An issue has occurred during processing. We are unable to complete the request at this time.

(CASE
WHEN `System Name`='' or `System Name` LIKE '' then 0 ELSE COUNT(DISTINCT `System Name`) END)

 

I've also tried doing the count from the ETL and I'm able to get 0's to show up on the dataset, but not on the chart.  Also, when I do it through the ETL, it takes hours to process due to the number of rows. 

 

Currently, I'm trying to blend the calendar and SQL data matching the dt and 'batch date' columns. I'm just at a loss on what to do here. Any thoughts?

Comments

  • rahul93
    rahul93 Contributor

    Are those values NULL or blank (''), I would guess its a NULL since you are left joining with the calendar dates and if the other dataset doesnt have the values then it gives a NULL in SQL.Either way this should work: 

    (CASE
    WHEN `System Name`='' or `System Name` is NULL then 0 ELSE Count(DISTINCT `System Name`) END)

  • I get the same error with that.

  • rahul93
    rahul93 Contributor

    I could get it to work :(


    try this: 

    CASE

    WHEN TRIM(`System Name`)='' or `System Name` is NULL  then 0 ELSE count(distinct `System Name`) END

  • That one says the formula is invalid. I tried it anyway but still get the same error.

  • rahul93
    rahul93 Contributor

    I made an edit can you please try that.

  • rahul93
    rahul93 Contributor

    Try now had left a random or in the middle :X

  • Valid query, same error.

  • @jlazerus If I understand what you're trying to do, you want to get a distinct count of all none Null or blank values found?

     

    If so you can try this:

    COUNT (DISTINCT (CASE
    WHEN `System Name` IS NOT NULL AND `System Name` <> '' THEN `System Name` END))

     

    Hope that helps,

    ValiantSpur

  • Just to clarify, I'm trying to get a count of the number of distinct system names, even when the field is null. So in those cases, the count would be 0. I did try what you wrote and the error went away, but the chart says 'No data exists'.

  • If you also want a distinct count to include nulls then you'll add this:

    COUNT (DISTINCT (CASE
    WHEN `System Name` IS NOT NULL AND `System Name` <> '' THEN `System Name` ELSE 'Blank' END))

    If there are no valid system names found (only blank or null) your count returned should be 1.

  • I just don't want to see 1 on my chart when there are really 0.  I don't want to count the null field. I just want it to show as 0 on the chart when it is null.

  • rahul93
    rahul93 Contributor

    That error was because you were trying to use an aggregate function inside of a case statement.

  • @jlazerus If you want 0 when only null or blanks are present you can do try this:

    CASE WHEN COUNT (DISTINCT (CASE
    WHEN `System Name` IS NOT NULL AND `System Name` <> '' THEN `System Name` END))
    > 0 THEN
    COUNT (DISTINCT (CASE
    WHEN `System Name` IS NOT NULL AND `System Name` <> '' THEN `System Name` END))
    ELSE 0
    END
  • Still says 'No Data Exists'

  • rahul93
    rahul93 Contributor

    try using the TRIM function after the `system_name` <> ''. I think the data might have blank system names as ' ' or maybe with more spaces in them. 


    Also, i dont think using distinct would produce the right result as the value is calculated row by row (my understanding), so the distinct will only match one to one which is always distinct

  • There is another thread that was solved for this same question here.

    Please let me know if this helps everyone out.

    Thanks!