Forum Discussion

LON's avatar
LON
Helper I
9 years ago
Solved

Handling Empty Results

Hi

 

I have a query which returns a list of issues in jason format which I then transform into a table and visualize.  The problem is when no rows are returned i.e. no issues - so then there is no table to visualise.       What I would like to do is display a "zero issues" card or whatever in my report.  

 

Hope you can help please?

  • Anonymous's avatar
    Anonymous
    9 years ago

    LON,

    Change your code as follows. And maybe you would need to change List.IsEmpty(content) part in the following code to List.IsEmpty(Source) or List.IsEmpty(body), you can test it.

    let
    
    Source = Json.Document(Web.Contents("https://xxxxxxxxxxxxx", [Headers=[zzzzz="xxxxxx"]])),
    body = Source[body],
    content = body[content],
    #"Converted to Table" = Table.FromList(content, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    Table1=Table.FromRecords({
            [Column1 = ""]
            
        }),
         result= if List.IsEmpty(content) then Table1 else #"Converted to Table" 
    in
         result
    



    Regards,

15 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi LON

     

    That depends on what is missing. Is there a date-column in your data?

    • LON's avatar
      LON
      Helper I

      Hi Anonymous

       

      Thanks very much for getting in touch so quickly....

       

      I checked the dat and there is no date column.  

       

      The report works fine when there is data retirned which is then converted from json into a table but when there is no data returned by the query there is no table created in that step.   Hope this helps explain.

       

      Best Regards

       

      Liam

      • Anonymous's avatar
        Anonymous
        Not applicable

        LON

         

         

        The reason I'm asking is you probably need to make a new table to have the ability to show 0's for rows where there is no data. The solution to this depends on whether you have date-data or not.

         

        If you have date-data, I would try to create a seperate date table and then create a relation between them in order to display blanks or zeros. You could try a similar method for something else than dates. Let me know if this makes sense. I'll gladly elaborate for you.

         

        Best,

        Martin

  • Anonymous's avatar
    Anonymous
    Not applicable

    LON,

    Could you please share the query or sample data of your table for us to analyze? We also need to know where you perform the query.  

    Regards,
    Lydia

    • LON's avatar
      LON
      Helper I

      Hi Lydia,

       

      Thanks very much for your help.

       

      Please see the images below - these are taken after the Convert to Table step in the Query Editor.

       

      In the first case there is data in the json but in the 2nd case there is no data returned.

       

      What I would like to do is to have a a table resulting with the same field names and so that the subsequent query steps will not result in an error (eg. column not found).

       

       

      I hope this makes sense - just let me know if you need more information

       

      Best Regards

       

      Liam

       

       

       

       

       

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        LON,

        Add new blank query in Power BI Desktop, paste the following code in the Advanced Editor of the blank query.

        let
            Source = Json.Document(File.Contents("YourPath\JSONFileName.json")),
            #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
            Table1=Table.FromRecords({
                [Column1 = ""]
                
            }),
             result= if List.IsEmpty(Source) then Table1 else #"Converted to Table" 
        in
             result



        Regards,
        Lydia