Is it possible to provide USERPRINCIPALNAME in a Calculated Column? - powerbi

I have a requirement in my project where I have to concatenate the e-mail ID of the report user in a column.
The Column where this has to be done is a web-link that redirects to a different application.
So for eg: the data in the columns is "**www.abc.html?/powerbi**".
My result should be "**www.abc.html?/powerbi,emailid#company.com**"
I want to get the email id of the user who is accessing he report.
I am not able to use USERPRINCIPALNAME() in calculated columns. Is there any alternate way to achieve this ?
Thanks in Advance.
Best Regards,
Pratik

Columns are created at refresh time, and it would not make sense to include things like USERPRINCIPALNAME in a column.
Measures are calculated at query time, and can contain these things. You could try to incorporate this in a measure instead.

You can concatenate the value of userprincipal() into a text field with a DAX query in a measure. An example of this is below:
WebUrl = www.abc.html?/powerbi,"&Userprincipal()&"/somefolder/"&FirstNonBlank(Table[ConcatText],Table[ConcatText]=Table[ConcatText])
If you need it with specific text from another field, you can force the text from the line by adding formula like FirstNonBlank() as below:
WebUrl2 = www.abc.html?/powerbi,"&Userprincipal()&FirstNonBlank(Table[TableName],TableName[Text]=TableName[Text])

Related

calculate time difference between two timstamp columns in direct query mode in PowerBI

I need to calculate the time difference between two timestamp columns in my table and create a new column with the calculated values but as I'm doing this in the direct query mode, I have some limitations for it.
I tried datediff, duration.totalseconds etc but nothing really worked..
A header
Another header
2022-07-02T21:09:13
2022-07-02T18:10:00
2022-07-03T06:09:35
2022-07-03T03:10:00
2022-07-03T03:08:41
2022-07-03T00:10:00
2022-07-02T15:09:29
2022-07-02T12:10:00
2022-07-05T00:09:22
2022-07-04T21:10:00
2022-07-02T12:09:34
022-07-02T08:30:00
I was able to achieve the result I want through my sql query
select (unix_timestamp(timestamp1)-unix_timestamp(timestamp2))/3600 as hourly_diff from table1
hourly_diff
2.9869444444444446
2.9930555555555554
2.9780555555555557
2.991388888888889
2.9894444444444446
3.6594444444444445
2.9716666666666667
3.0055555555555555
This is the result I'm getting with my sql query and I want the same result with DAX..
Anyone could help me with this query?
Thanks in advnance

Power BI DAX - Measure to change name of row value

I need some help creating a measure to change the name of "FROM_USER" in the slicer here.
I think I need to use the function SELECTEDVALUE, but I have not managed to get it working.
So, the column has only two values, CRAWLER and FROM_USER.
Any suggestions would be helpful!
See picture
Measures can't be used as slicer values. If you want the column values to be changed and yet to be used in a slicer, you need to create a calculate column to change that.
Column = IF('Table'[Column1]="FROM_USER","desiredValue","CRAWLER")
If you are really keen on using a measure to slice, you need to build a disconnected table and follow the method described here. But the performance will take a hit depending on how complex your data model and calculations are.

Is there a way to return the name of the selected bookmark in Power BI? Something like the selectedvalue() command

Hi I'm looking for a DAX code that can return the name of the selected bookmark. Thanks.
You can't. There is no DAX function to do exactly that.
There are (tedious) workarounds that would allow you to do that. One could be to have a table that would have all names of your bookmarks, then each of your bookmark would set a page level filter on that table (to the value equal to the name of your bookmark). That way, you can get SELECTEDVALUE from the filtered table of bookmark names.
Since you refuse to elaborate on your question, that's all I can give you.

How to filter on column name in PowerBI

enter image description here
I want to add filter on each column like Excel filter. I already researched all solution but not find any good way.
I think this should work without knowing what any of your data or setup looks like.
In the Query editor, go to the Transform tab. Use First Row as
Headers.
Select the column that you'd like to and make sure to unpivot any
columns associated.
Rename the columns ( if necessary )
Close and Apply.
If you provide a some additional detail on the data, how it's currently configured, etc. I think it would make it easier to help.

Select Columns from multiple tables - Django

I am trying to select all the columns from one table and only a single column from the second table using the Django ORM.The two tables are related by a foreign key but the column in the second table which i want, is not related, so using select_related doesn't work.
I used
FirstTable.objects.filter().values("All first table columns separated by a comma","second tablename__column name")
and this worked fine. Since, the columns are very large in number, i do not want to list all of them in "values". So, i am looking for an easy way to do this.
Thanks for your help
EDIT:
Thanks for the help! I was able to get it working by using annotate like the following.
FirstTable.objects.filter().annotate(variable_name=F("SecondtableFieldName"))
You Can use the extra method in this.
FirstTable.objects.filter().extra("write down here what every yo want")