cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Push data with CSharp

Hi,

 

I'm working on getting my data-pushed with c# and the power bi API, my issue is with datetime columns; My explanation, in my code, when I created the dataset I'm specificating the type of my data, if the column is string, I'm sending string, when is Datetime I send DateTime, in this part my process work perfect ( O at less is what I think it is). When I'm tring to push the data, my datetime format is "yyyy-MM-ddTHH:mm:ss.fffZ" and when execute the push work fine, but in my power bi desktop the column isn't marked as datetime and when I try to work with a datetime function is telling me that cannot convert value text to date, this is the message.

 

martinmatouy_0-1593476749222.png

 

I'm assuming that my data isn't in the correct format in power bi dataset, what is driving me crazy.

If someone can give me the help I'll appreciate

 

Thanks for the help

 

7 REPLIES 7
Highlighted
Resident Rockstar
Resident Rockstar

Re: Push data with CSharp

Power BI has a different type for that - it is called DateTimeZone. If it still doesn't work then you can replace the T by a space and remove the Z before converting to DateTime. (assuming that you want to keep your time as UTC)

 

Here's an example 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA1MNM1sgwxNLUyMLcyMtEzMDCIUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type datetimezone}})
in
    #"Changed Type"
Highlighted
Regular Visitor

Re: Push data with CSharp

Thanks, Ibendlin for your message, I tried removing the T between the date and the time and the Z at the end of my DateTime, but I still have the same message regarding the text type.

 

One thing I forgot to tell is that my data in my c sharp process, from a SQL Server DB.

 

I don't familiarize with the part of the code you tell me, can you explain a little more, please?

 

Thank again.

Highlighted
Resident Rockstar
Resident Rockstar

Re: Push data with CSharp

Did you try my example?  Test it with one of your strings.

Highlighted
Regular Visitor

Re: Push data with CSharp

Sorry lbendlin, I don't familiarize with that code, where should I run?

Highlighted
Resident Rockstar
Resident Rockstar

Re: Push data with CSharp

That is Power Query code. Run it in Excel or in Power BI Desktop.

Highlighted
Regular Visitor

Re: Push data with CSharp

Thanks again lbendlin, when I use my Desktop version, I'm unable to select an option, it looks like disabled.

 

martinmatouy_0-1593538337640.png

 

 

 

Highlighted
Regular Visitor

Re: Push data with CSharp

Well, unfortunately, the issue was my CSharp code, I was sending the data type incorrectly.

 

I made the change to the data set creation process with the correct data type (Datetime) and It's working. I'm fighting now with the hierarchy of the dates fields because the streaming dataset isn't available but I have my original problem resolve.


Thank you so much for the time.

Helpful resources

Announcements
May 2020 Community Highlights

May 2020 Community Highlights

It’s time for another PBI Community recap!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Top Solution Authors