Remove seconds from the timestamp field in PowerBI - powerbi

I am new to PowerBI and hence this question might be very simple but it would be very helpful if you help me with it.
I have a field in my table "A_Timestamp" and the value is
01/02/18 12:08:25
I want to ignore the seconds and display the result as
01/02/18 12:08
How can this be achieved?
Thank you very much in advance.
Regards,
Ani

I would use the Query Editor and add a Custom Column, with a calculation something like the following:
= DateTime.From ( DateTime.ToText( [A_Timestamp] , "yyyy-MM-dd HH:mm") )
You can then add steps to remove the original A_Timestamp column, rename the added column, and reset the datatype to Date/Time.

Related

Get a Department Percent Contribution of Total Sales

Table = opportunity
Dimension Field = Territory
Measure Field = AnnualSales
I want a measure that will take a territories SUM(AnnualSales) and see what percentage it makes of All territories SUM(AnnualSales) would be. I have not been able to accomplish this based off the articles I've read so far. Any help is greatly appreciated
My results would look something like this.
If you want to see results in a table of visualization:
create this measure: CALCULATE(SUM(AnnualSales))
then, drag Territory field in a table, add the new measure created in the table and then go to visualization editor right click on measure and click on show results as a percent of column total.
Waiting your answer ... :)
Regards
I was able to accomplish what I set out with the following.
cm_TotalEstAnnualSales = Calculate(Sum(opportunity[Est. Revenue (Annualized)]),All(opportunity))
cm_PctofTotalEstAnnualSales = Divide(SUM(opportunity[Est. Revenue (Annualized)]),[cm_TotalEstAnnualSales],0)
Thanks for the tips here!

How to select the last value of the day with DAX in Power BI

I am new to power BI and stuck with an issue. I have my model as follows:
Date Dimension
Measurement Fact
The date column in Date Dimension is link to measuredate in Measurement Fact
Below is a sample data:
NB: In edit query, I have changed the type of measuredate to Date only.
I have tried the measure below but it doesn't work the way I want. It will sum all the values of the day but what I want is the last value of the day:
day_fuel_consumption =
CALCULATE (
SUM ( measurement[measurementvalue] ),
FILTER (
measurement,
measurement[metername] = "C-FUEL"
&& measurement[measuredate] = MAX ( measurement[measuredate] )
)
)
My Goal is to get 29242, i.e the last value of the day. Remember that measuredate is a Date field and not Datetime (I changed to Date field so that my Year and Month filter can work correctly). I have changed the type in edit query.
Changing your measure to use a variable could be the solution:
DFC =
var maxDate = MAX(measurement[measuredate])
return
CALCULATE(
SUM(measurement[measurementvalue]),
measurement[measuredate] = maxDate
)
However, you should keep the datetime format for measureDate. If you don't want to see the time stamp just change the format I power bi. Otherwise power bi will see two values with max date and sum them, instead of taking the last one.
Well, if you want to avoid creating a measure, you could drag the fields you are filtering over to the visual filters pane. Click your visual, and scroll a tiny bit and you will see the section I am referring to. From there, just drag the field you are trying to filter In this case, your value. Then select "Top N". It will allow you to select a top (number) or bottom (number) based on another field. Strange enough, it does allow you to do top value by top value. It doesn't make sense when you say it out loud, but it works all the same.
This will show you the top values for whatever value field you are trying to use. As an added bonus, you can show how little or how many you want, on the fly.
As far as DAX goes, I'm afraid I am a little DAX illiterate compared to some other folks that may be able to help you.
I had to create two separate measures as shown below for this to work as I wanted:
max_measurement_id_cf = CALCULATE(MAX(measurement[measurementid]), FILTER(measurement, measurement[metername] = "C-FUEL"))
DFC =
var max_id_cf = [max_measurement_id_cf]
return
CALCULATE(SUM(measurement[measurementvalue]), measurement[measurementid] = max_id_cf)

Trying to Reorder Columns in Data View in Power BI

Is there a way I can reorder columns in 'Data View' within Power BI? I tried doing it in Power Query first but when the data loads into the table, the columns automatically rearrange.
Edit after comment.
There is easy fix to enforce column order just as in Power Query:
In Power Query Editor > Disable Query Load. Close and Apply.
Open the Query Editor again, enable the Query Load. Refresh the Query. Then Close and Apply.
Answer to misunderstood question.
This may be interesting solution in M PowerQuery. The function below let you reorder columns by only stating few columns from the whole set of columns. Add this in blank query and rename it to FnReorderColumnsSubset.
(tbl as table, reorderedColumns as list, offset as number) as table =>
Table.ReorderColumns
(
tbl,
List.InsertRange
(
List.Difference
(
Table.ColumnNames(tbl),
reorderedColumns
),
offset,
reorderedColumns
)
)
Use it as this:
= FnReorderColumnsSubset( Source, { "Region", "RegionManager", "HeadCount" }, 0 )
Found it here:
https://datachant.com/2017/01/18/power-bi-pitfall-4/
It is extremely stupid way, but it is working - i found it by accident:
In edit query view remove the column, then save changes. You will see that in data view that column was removed as well.
Now again in edit query view remove from applied steps the action that removed the column. Save it again.
You will see that removed previously column was added to the end of the table.
This way you can arrange your columns to have it the way you want it in data view.
Hope it helped.
I don't know that you can rearrange an existing table, but if you re-create it as a new table, you can pick the order you want.
NewTable =
SELECTCOLUMNS (
OldTable,
"Column1", OldTable[Column1],
"Column2", OldTable[Column2],
"Column3", OldTable[Column3]
)
I think most here have misunderstood the problem, except #Jacko. So far as I know it is now possible to re-arrange columns in Power Query and load to the model and the table will load in the column order you specified in PQ. The problem is in dataview in the modelling layer of PBi. Here you can add many calculated columns, but, any new column you add is always placed at far right and can't be moved. Yes, I know about SELECTCOLUMNS but it isn't a solution as the new table does not have the editable formulae. A solution is a drag and drop feature of some sort. PBi users are still waiting for it despite the problem being flagged in MS Forums some years ago. No progress TIKO other than the limp SELECTCOLUMNS solution.

Return table with rows where certain column is blank

I thinks this is a very easy to answer question ,but I cant figure it out and im very beginner in DAX.
I have this sample data set:
I want to return a Table in powerbi with only the rows where job is blank. So it would look like this:
How to do this? :)
Because you mentioned DAX, you may use this expression to return a Table with only the rows, where job is blank:
FILTER('Table','Table'[job] = BLANK())
But I guess, it make sense for you only inside the measures, you want to calculate.
Click on the button in the title for job column and uncheck all values, except (Blank):

Date comparison in power bi dax

I had a problem with my code. It returns the below error:
DAX comparison operates do not support comparing values of type date with values of type text.
Basically, I want to count rows based on some conditions. And I know there is a need to convert the data type, but I am not sure how to do it.
Total Open Issues =
--------------------
--basic info
VAR SELECTEDDATE =
DATEVALUE(SELECTEDVALUE(Calender[FullDateAlternateKey].[Date]))
--------------------
--FIND the relvent data
VAR rlvttable =
calculatetable(
Tracker,
Tracker[Catagory]="ISSUE",
DATEVALUE(Tracker[ClosedDate])>SELECTEDDATE
||Tracker[ClosedDate]=""
)
--------------------
--Results
Return
countrows(rlvttable)
Anyone could advise me how to correct it? Thanks~
Check the data type of columns Tracker[ClosedDate] and Calender[FullDateAlternateKey] - one of them is Text, rather than Date.
To fix, you could:
choose a different field which is already a Date format
change the format of the offending column
use DATEVALUE in your measure, to convert the text date to a real date.
It also looks like you need to edit this statement, as these conditions conflict:
Tracker[ClosedDate]>SELECTEDDATE
&&Tracker[ClosedDate]=""
I am trying to compare the closedDate with "". I should use blank() instead.